问题
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?
回答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();
}
});
来源:https://stackoverflow.com/questions/13880780/how-to-handle-multiple-listeners-inside-gridview-in-android