I have to show a list with different type of Views. So I have to define a ListView with an Adapter where I have to inflate multiple views. I have gone through example given, but problem is for my list is not symmetric like the example where header is repeated each time after 4 items. So I am facing problem with reuse of items in getView()
public View getView(int position, View convertView, ViewGroup parent) {
int type = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
switch (type) {
case TYPE_1:
convertView = mInflater.inflate(R.layout.item1, null);
.......
break;
case TYPE_2:
convertView = mInflater.inflate(R.layout.item2, null);
.......
break;
}
convertView.setTag(holder);
} else {
holder = (ViewHolder)convertView.getTag();
}
............
............
}
Now if the convertView is not null, but the item type for which it was earlier used was different, then the layout will not match with same. How this code will handle this issue?