I am using grid view with ImageAdapter to display images.
I have two set of images that is mThumbIds containing original images and cThumbIds containing the selected images.
Right now when i click on an image i change the normal image with the selected image. The code is as below:
final ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
iv.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//iv.setColorFilter(Color.LTGRAY);
iv.setImageResource(cThumbIds[position]);
//iv.bringToFront();
index= position;
}
});
iv.setImageResource(mThumbIds[position]);
But the problem arises when i click on the another image the other image also shows as selected. The correct way would be to show the new image as selected and remove the older one as selected .In other words the older one should revert back to original one.
Please help me on this
Thanks,
Pankaj
I’m assuming you are using a modified copy of the
ImageAdapterclass in this tutorial and that the code you have posted is in thegetView(int,View,ViewGroup)method of that class.You save the index of the image that is selected but you don’t save the view itself. You need to save both in order to revert the old image, something like this:
I’m a bit confused about the line
ImageView iv = (ImageView) v.findViewById(R.id.icon_image);though (as I mention in my code example).