I have a ListView
adapter which is set with different layouts according to the type of the row item.
If I recycle my rows using a holder, as shown in the code below, I think I'll get some errors because for a recycled row I'll get the layout of the latest non-recycled row, which might not be of the same type.
Should I avoid recycling the rows in that case? What other options do I have?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
MyHolder holder = null;
int type = getItemViewType(position);
if(row == null)
{
holder = new MyHolder();
LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
if(type == TYPE_1){
row = inflater.inflate(R.layout.layout_type_1, parent, false);
}
else if(type == TYPE_2){
row = inflater.inflate(R.layout.layout_type_2, parent, false);
}
else {
row = inflater.inflate(R.layout.layout_type_3, parent, false);
}
row.setTag(holder);
}
else
{
holder = (MyHolder)row.getTag();
}
/* ... */
}