Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning true and false in OnTouch?

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

like image 270
SoliQuiD Avatar asked Jun 18 '14 13:06

SoliQuiD


People also ask

What happens if Ontouch returns false?

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.

What is onTouchEvent?

onTouchEvent is a method implemented by the View, Activity and other base classes like LinearLayout, etc.. public boolean onTouchEvent(MotionEvent event) { throw new RuntimeException("Stub!" ); } you can override this method by any derived classes.


1 Answers

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!

like image 162
Xaver Kapeller Avatar answered Nov 12 '22 07:11

Xaver Kapeller