2

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

Thanks

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
mohan
  • 13,035
  • 29
  • 108
  • 178

2 Answers2

8

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.

penghaitao
  • 226
  • 1
  • 3
  • 11
2

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)
}
WarrenFaith
  • 57,492
  • 25
  • 134
  • 150