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 ?
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.
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.
To include the Event Handler in your application, you should know the following three concepts: Event Listeners. Event Handlers. Event Listener Registration.
onFocusChange() From View. OnFocusChangeListener . This is called when the user navigates onto or away from the item, using the navigation-keys or trackball. onKey()
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With