I am implementing a ListFragment using a custom ArrayAdapter to populate the list. Each row item has an ImageView and three TextViews. Data is being parsed via XML and the i
First of all define in getView()
method into convertView=null;
and comment else condition in this method and add int type = getItemViewType(position)
;.
Also remove static keyword from each View item like Textview, ImageView
in ViewHolder class.
NOTE: override getViewTypeCount() and getItemViewType() in your adapter.
if(convertView == null){
switch (type) {
case 0:
//First view[Row layout]
break;
case 1:
//Second view[Row layout]
break;
//another Case here....
convertView.setTag(holder);
//remove else part when used convertView =null;
/*else {
holder = (MyViewHolder) row.getTag();
}*/
}
@Override
public int getItemViewType(int position) {
// TODO Auto-generated method stub
map = list.get(position);
message_type = map.get("message_type");
if (message_type.equalsIgnoreCase("TEXT")) {
return 0;
} else {
return 1;
}
}
@Override
public int getViewTypeCount() {
// TODO Auto-generated method stub
if (getCount() != 0)
return getCount();
return 2;
}
Do it now! Done!