I need to create a ListView
and show more detailed layout only for the selected row in order to show more information to the costumer. What I tried is below:
newsListView.setAdapter(new NewsListAdapter(this, news));
newsListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Here I tried to change layout of this row only
view = inflater.inflate(R.layout.listitem_news_selected, null);
TextView info = (TextView) view.findViewById(R.id.info);
NewsData news = (NewsData) parent.getItemAtPosition(position);
info.setText(news.getInfo());
}
});
And here is the NewsListAdapter
:
public class NewsListAdapter extends BaseAdapter {
List<NewsData> items;
Activity context;
/* private view holder class */
private class ViewHolder {
TextView title;
ImageView image;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listitem_news, null);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.title);
holder.image = (ImageView) convertView.findViewById(R.id.imageView1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
NewsData news = items.get(position);
holder.title.setText(news.getTitle());
new DownloadImageTask(holder.image).execute(news.getImgUrl());
return convertView;
}
}
In this question, similar question was asked but it didn't help me. I am guessing I need to do something with Adapter but I got stuck here. Any ideas will be appreciated.