0

I need to handle when a user "clicks" (taps) on the background of a GridView (ie. outside of an item).

When I add an onClickListener to the GridView I get the following error:

Caused by java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead
       at android.widget.AdapterView.setOnClickListener(AdapterView.java:777)

It seems the parent AdapterView overrides the setOnCLickListener and just throws an error.

I have tried adding an onClickListener to the parent view of the grid view, but it is never called when you tap on the background of the GridView.

How is it possible to implement this functionality?

All the stackoverflow questions I have seen seem to be for people who actually need to to call setOnItemClickListener, but this is not the case for me. The OnItemClickListener is not called in this case.

Piers Geyman
  • 479
  • 3
  • 19

1 Answers1

1

May be you can try setOnTouchListener on the gridview and use the MotionEvent.ACTION_DOWN in onTouch method

Smit Davda
  • 638
  • 5
  • 15
  • I just had a look at this option and it gets called when I click on the background, but it also gets called when I click on an item in the grid before the onItemClickListener is called. Using the following http://stackoverflow.com/a/13809839/2199475 I was able to filter out the item clicks. Thanks!! – Piers Geyman Aug 10 '16 at 11:04