I’m trying to update my custom ArrayAdapter, but after calling updateListArray getView is called and the convertview is not null but the tag is null, giving me errors. If I make an extra null check and set a new viewholder it simply shows the wrong content.
I simply can’t figure out why this gives me problems, I have following in code:
public class CustomAdapter extends ArrayAdapter<Item> {
private ArrayList<Item> mListItems;
public CustomAdapter (Context context, int rowResourceId, ArrayList<Item> items) {
super(context, rowResourceId, items);
mListItems = items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null) {
// setup holder
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.list_row, null);
holder.mEventStart = (TextView) convertView.findViewById(R.id.row_date);
holder.mTitle = (TextView) convertView.findViewById(R.id.row_artist);
holder.mSubTitle = (TextView) convertView.findViewById(R.id.row_description);
holder.mImage = (ImageView) convertView.findViewById(R.id.row_artist_image);
holder.mScene = (ImageView) convertView.findViewById(R.id.row_scene_image);
holder.mStatus = (ImageView) convertView.findViewById(R.id.row_new);
holder.mRowParent = (View) convertView.findViewById(R.id.row_parent);
} else {
// get existing row view
holder = (ViewHolder) convertView.getTag();
}
//setup row view content
if(!mListItems.isEmpty()) {
//set content
}
return convertView;
}
public void updateListArray(ArrayList<Item> list) {
this.clear();
for(Item item : list) {
this.add(item);
}
mListItems = list;
notifyDataSetChanged();
}
getTag() will be null unless you have used setTag(). It will probably work as you want if you remove the call to getTag()