Reputation: 36
How can I detect when the touch event is over in Android,in Webviews specifically.
pseudocode: if (touch event is over) then do something end
Thanks!
Upvotes: 0
Views: 1005
Reputation: 22474
The MotionEvent
object passed to the onTouchEvent(...)
method has a getAction() method, you can use it to determine if the event is over. eg:
webViews.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//pointer down.
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_OUTSIDE:
//event has finished, pointer is up or event was canceled or the pointer is outside of the view's bounds
break;
}
return false;
}
}
Also, if you want to consume the event (stop it from propagating) just make the onTouch(...)
method return true
instead of false
.
Upvotes: 3