Question

can anybody give example how to implement gesture detector onfling in webview in android

Thanks

Was it helpful?

Solution

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.

OTHER TIPS

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)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top