I have a grid view of images. When click on an image I set a little check mark drawable to mark it as selected, and when another item is clicked I go through all items and remove the check mark.
The problem is my first item in the grid view does not get updated after it is checked. It simply does not do anything after it is checked. All other items work as expected - they get checked when clicked and unchecked when another item is clicked. Only the first item stays checked when it is clicked and does not change when other items are clicked.
Below is the onItemClickListener code. Any ideas?
for (int i = 0; i < shapeIds.length; i++) {
ImageView imageView = (ImageView) adapterView.getItemAtPosition(i);
imageView.setImageDrawable(null); // does not work on item 0
}
Drawable check = VectorDrawableCompat.create(getResources(), R.drawable.check_circle, null);
((ImageView) view).setImageDrawable(check);
EDIT: Adding more code to help understand the issue. Here is my adapter code:
public class ImageAdapter extends BaseAdapter {
private Context context;
private ImageView imageView;
private int[] itemIds;
private ImageView[] views;
ImageAdapter(Context c, int[] itemIds) {
context = c;
this.itemIds = itemIds;
views = new ImageView[itemIds.length];
}
@Override
public int getCount() {
return itemIds.length;
}
@Override
public Object getItem(int position) {
return views[position];
}
@Override
public long getItemId(int position) {
return itemIds[position];
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
imageView = new ImageView(context);
Drawable mainDrawable = VectorDrawableCompat.create(getResources(), itemIds[position], null);
imageView.setBackground(mainDrawable);
views[position] = imageView;
return imageView;
}
}