Question

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?

Was it helpful?

Solution 2

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.

OTHER TIPS

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

You should be setting onClickListener for each ImageView inside Adapter's getView() method. Also, set setItemsCanFocus(boolean itemsCanFocus) true on ListView.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top