I have some weird events occurring in getView() method in custom adapter for listview. It seems as if cached views are only updated during app's end. I've read a bunch of tutorials, but never seen an issue like this.
When I add first item to an adapter, everything is fine - convertView is null, I inflate view and return it. However, when I try adding second item, getView() gets sent exactly the same convertView, for position 0 and 1 (even though for position 1 it should be null), resulting in identical items.
After restarting app, every added item is viewed properly (data is serialized), but trying to add more items still results in views identical to the first one.
I'm sure the problem lays in adapter, getView(), because when I stop using convertView and just inflate items every single time, it works perfectly fine.
This is how my methods look like. mNames is Vector; when it changes, it's serialized and the adapter is notified. This vector sets adapter count (see getCount). It's deserialized in onCreate(), right before being passed to adapter.
@Override
public int getCount() {
return mNames.size();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if(convertView == null) {
convertView = layoutInflater.inflate(R.layout.grouplist_listview_item, null);
//just saying, there are more subviews; I didn't find it relevant
((TextView)convertView.findViewById(R.id.grouplist_listview_item_text)).setText(mNames.elementAt(position));
}
return convertView;
}
So I don't really understand two things here:
- Why all getView() calls are made with the same convertView?
- Why they aren't sent like this during app start and it works then?
((TextView)convertView.findViewById(R.id.grouplist_listview_item_text)).setText(mNames.elementAt(position));outside the if - Blackbelt