Question

I am creating a game that requires a SurfaceView to implement OnTouchListener. During the game I want to pause the Listener for some specific time.I tried returning false from the onTouch() method , but still the method keeps executing.Is there any other way to have the listener paused for sometime? And anyone please explain what returning false from onTouch() actually mean?

Was it helpful?

Solution

From the View documentation:

Returns
True if the listener has consumed the event, false otherwise.

If you return true you tell android that the press is taken care of. Forget it.

If you return false you basically say "Not my problem, Someone else will have to take care of this click". Then android will pass the event down to other views, which could be under your view.

OTHER TIPS

If you return true you signal the system that you have consumed the event as seen in the documentation. This means that other views that also have a touchlistener will not get this event for handling. If you return false the event will be passed to parent views for handling.

For example if you have a ListView nested inside a Viewpager the Listview is the first view that can handle the touchevent. If it is a horizontal swipe the event will not be handled through the listview and the viewpager will be able to handle the swipe.

you have to deregister your implementation. You can do it providing null as parameter. Set it again when your pause mode ends. If you return true, the touch event will not be passed to other possible views.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top