1

I have to use both onTouchListener() and onItemClickListener() on a ListView . But only OnTouch() is getting fired on clicking the listview.

From other posts, the preferred solution is to return false from onTouch() for the event to not be consumed. I am using only ACTION_UP and ACTION_DOWN and returning false from onTouch() but still onItemClick() is not working?

Also tried returning super.onTouchEvent(event); from onTouchListener(). Didnt work.

Diffy
  • 2,339
  • 3
  • 25
  • 47
  • I think you want onItemClickListener() on a ListView – CSmith Oct 22 '14 at 18:16
  • Yes onItemClickListener() actually. I will edit the question – Diffy Oct 22 '14 at 18:18
  • You cannot fix that, either you consume the touch event or you consume the click event, but you cannot do both because the click event requires the touch event not to be consumed. But you can always subclass `ListView` and override `onInterceptTouchEvent()` to get all the touch events without consuming them. – Xaver Kapeller Oct 22 '14 at 18:21
  • @XaverKapeller actually my purpose of using onItemClick() was to get the child view on which click was done. Using onTouch(), its a little tedious. – Diffy Oct 22 '14 at 18:30
  • What are you saying? You asked if you can listen to touch events and click events at the same time, but that is not possible. You can only do it but overriding `onInterceptTouchEvent()`. – Xaver Kapeller Oct 22 '14 at 18:33
  • Yes my onTouch() is working fine. I want to use onItemClick() to find out the childview that was clicked – Diffy Oct 22 '14 at 18:34
  • @XaverKapeller, so can i use onItemClick() and onTouch() both by overriding onInterceptTouchEvent()? – Diffy Oct 22 '14 at 18:39
  • No you can use `onInterceptTouchEvent()` instead of `onTouch()`. The difference between the two is that you are forced to consume the touch events in `onTouch()` which will result in the click listener not working, but `onInterceptTouchEvent()` intercepts all touch events of the `ViewGroup` and its children without consuming the touch events. Just be sure to always return false in `onInterceptTouchEvent()`. – Xaver Kapeller Oct 22 '14 at 18:51

0 Answers0