Does it matter if i return true
or false
in onTouch()
of an OnTouchListener
?
I can't see any difference between returning true
or false
in this example: Android Swipe on List
Asked
Active
Viewed 1.1k times
1 Answers
34
The return value determines if you consumed the touch event.
In other words true
means that this touch event is interesting to you and all follow up calls of this touch event like ACTION_MOVE
or ACTION_UP
will be delivered to you.
If you return false
than the touch event will be passed to the next View
further up in the view hierarchy and you will receive no follow up calls. The touch event will continue to be passed further up the view hierarchy until someone consumes it.
If you have any further questions please feel free to ask!

Xaver Kapeller
- 49,491
- 11
- 98
- 86
-
1Ok thats explains it very well but let me be more specific... I was asking on the provided link, the answer returns false in some cases (on the mouse_down for example)... What i notice if i used simillar coding is that the onTouch captures only the down then doesnt capture anything else (action_move or action_up) because it already returned false – SoliQuiD Jun 20 '14 at 14:44
-
Yes, as I explained in my answer if you return false you get the initial events and not the follow up events, sometimes you need to do it this way if for example you want to do something on `ACTION_DOWN` but don't want to consume the touch event because some other `View` depends on it. – Xaver Kapeller Jun 20 '14 at 15:12
-
In the answer you link to notes there is a comment in the code which states that the reason for returning false is that he wants the `View` to still be able to process click events. If he returned true there the touch event would be consumed by his touch handler and the `View` would never receive the touch event and as such wouldn't be clickable. – Xaver Kapeller Jun 20 '14 at 15:18
-
But yes, your observation is true, the code in the answer you are linking to wouldn't work. The `OnTouchListener` would never receive `ACTION_UP` after returning `false` on `ACTION_DOWN`. – Xaver Kapeller Jun 20 '14 at 17:20
-
We're all going on the same line till now.... then why exactly are you using a return false when it will stop the onTouch everytime after the ACTION_DOWN @Xaver – SoliQuiD Jun 21 '14 at 13:39
-
I explained it twice now, read my comments, read my answer, it's all there. – Xaver Kapeller Jun 21 '14 at 14:29