I have GridView where items are views with image (ImageView) and title (TextView). I'd like to perform onClick operation on this ImageView, but not on the whole GridView item. If I use this code:
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
ImageView imageView = (ImageView) view.findViewById(R.id.image);
imageView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// some operation
}
});
}
});
only the second click on ImageView will provide me to do operation. How can I do operation on ImageView by the first click on GridView?
When the user clicks on the gridview, then you add an onclicklistener to the imageview, that's why you receive only the second click. In the adaper, when you create the imageview, you have to write the image's onlicklistener
Check : OnClickListener not working for first item in GridView
try :
Instead of setting the onClickListener on your GridView, set it on the ImageView itself inside your GridAdapter, inside your getView()
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With