Reputation: 13165
can anybody give example how to implement gesture detector onfling in webview in android
Thanks
Upvotes: 2
Views: 6621
Reputation: 256
I find this way from somewhere:
To have the gesture detected in a WebView, no need to subclass anything. You just need to add this in your activity:
@Override
public boolean dispatchTouchEvent(MotionEvent e){
super.dispatchTouchEvent(e);
return mGestureDetector.onTouchEvent(e);
}
Where mGestureDetector is initialized as new GestureDetector(this) on your onCreate(). This will intercept all the gesture events, give opportunity to your listener to do whatever your want with it, and send it back to WebView so behaviour won’t be affected.
Upvotes: 8
Reputation: 57682
Done that just today:
private final GestureDetector mGestureDetector = new GestureDetector(new CustomGestureListener());
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
return mGestureDetector.onTouchEvent(event);
}
private class CustomGestureListener extends GestureDetector.SimpleOnGestureListener {
// override this method: onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
}
Upvotes: 2