Say I want a dialog to .show()
when the user Touches a certain element and .hide()
once he releases it.
I found how to make the O开发者_如何学JAVAnTouchListener
. But is there any sort of OnReleaseListener
?
Thanks!
Thats actually included in the OnTouchListener
. It gives you a MotionEvent on the callback,
use MotionEvent.getAction()
and check if it equals MotionEvent.ACTION_UP
. That means the user released the finger.
Equally you can check for ACTION_DOWN
to differentiate the two.
onTouchListener
returns you a TouchEvent
object, which contains the current touch action, that can be retrieved by calling event.getAction()
. There are some actions, one of them are ACTION_DOWN
and ACTION_UP
: first tells you, that the user has touched some view, and second tells you that user has taken his finger off a view. Means onRelease
will be onTouch
with the ACTION_UP
action. Hope this helps.
精彩评论