Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is meaning of boolean value returned from an event-handling method in Android

In android, most event listener methods return a boolean value. What is that true/false value mean ? what will it result in to the subsequence events ?

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

Regarding to the above example, if return true in onTouch method,I found every touch event(DOWN,UP,MOVE,etc) has been captured according to my logView. On the contrary,if return false, onely the DOWN event been captured. So it's seemd that return false will prevent the event to propagate. Am I correct ?

Furthermore, in a OnGestureListener, many methods have to return a boolean value too. Do they have the same meaning ?

like image 412
John Wang Avatar asked Sep 20 '10 23:09

John Wang


People also ask

What will happen if your Ontouch () callback returns false instead of true?

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 do you mean by event handling in Android?

Event Handlers − When an event happens and we have registered an event listener for the event, the event listener calls the Event Handlers, which is the method that actually handles the event.

Which of the following is are ways to handle events in Android?

To include the Event Handler in your application, you should know the following three concepts: Event Listeners. Event Handlers. Event Listener Registration.

Which is called when the user navigates onto or away from the item?

onFocusChange() From View. OnFocusChangeListener . This is called when the user navigates onto or away from the item, using the navigation-keys or trackball. onKey()


1 Answers

If you return true from an ACTION_DOWN event you are interested in the rest of the events in that gesture. A "gesture" in this case means all events until the final ACTION_UP or ACTION_CANCEL. Returning false from an ACTION_DOWN means you do not want the event and other views will have the opportunity to handle it. If you have overlapping views this can be a sibling view. If not it will bubble up to the parent.

like image 50
adamp Avatar answered Oct 12 '22 08:10

adamp