What does the boolean returned from the event handling method in Android mean?

In android, most event listener methods return a boolean value. What does true / false mean? what does this lead to subsequence events?

class MyTouchListener implements OnTouchListener { @Override public boolean onTouch(View v, MotionEvent event) { logView.showEvent(event); return true; } } 

Regarding the above example, if return true in the onTouch method, I found that every touch event (DOWN, UP, MOVE, etc.) was recorded according to my log >. Conversely, if return is false, then the DOWN event occurs. Therefore, it seems that return false will prevent the event from propagating. Am I right?

In addition, in OnGestureListener many methods must also return a boolean value. Do they have the same meaning?

+85
android events return listener touch
Sep 20 '10 at 23:51
source share
4 answers

If you return true from the ACTION_DOWN event, you are interested in the remaining events in this gesture. "Gesture" in this case means all events until the final ACTION_UP or ACTION_CANCEL . Returning false from ACTION_DOWN means that you do not want the event and other views to be able to handle it. If you have overlapping views, it might be a sister view. If not, it will be a bubble to the parent.

+114
Sep 21 '10 at 1:08
source share

From the documentation: http://developer.android.com/reference/android/view/View.OnTouchListener.html#onTouch(android.view.View , android.view.MotionEvent)

"True if the listener consumes the event, false otherwise."

If you return true, the event will be processed. If false, it will go down one level.

+17
Sep 20 '10 at 23:56
source share

A boolean value determines whether an event is consumed or not.

Yes you are right. If you return false, the next listener will handle the event. If it returns true, the event will be consumed by your listener and not sent to the next method.

+10
Sep 20 '10 at 23:55
source share

I lost almost one day in troubleshooting, but I found out that my onTouch function is called 2 times when using true and 1 time when using false.

+1
Jun 14 '13 at 14:58
source share



All Articles