0

In my app, a GridView has list of contents. Each item is inflated with a layout. Single item inside the gridview contains, an image and 2 textviews.

I have a requirement that when I click on the image, the image should be replaced with another image and when I click on any other places it should open a popup. I am able to listen to the second event, using OnItemClickListener. It opens the popup. How can I handle the first case? I mean how can I listen to OnClick event of image?

Vikalp Patel
  • 10,669
  • 6
  • 61
  • 96
intrepidkarthi
  • 3,104
  • 8
  • 42
  • 75
  • set an `OnClickClistener` for the image.. you could even set up a switch statement in your listener to decide what to do if the image is clicked and a default condition. what have you tried so far? – mango Dec 14 '12 at 14:45
  • @mango The below answer worked for me – intrepidkarthi Dec 14 '12 at 15:02

1 Answers1

1

In your view adapter, when you set the image resource, also set an onClickListener for the ImageView.

In my case, holder is a temporary static class which holds 2 TextViews and an ImageView.:

holder.mThumbnailImageView = (ImageView) convertView.findViewById(R.list.thumb);
holder.mThumbnailImageView.setImageResource(thisOrder.getIconValue());
holder.mThumbnailImageView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Toast.makeText(parent.getContext(), "image clicked: " + view.getId(), Toast.LENGTH_SHORT).show();
    }
});
jamis0n
  • 3,610
  • 8
  • 34
  • 50