According to android training if you extend GestureDetector.SimpleOnGestureListener
, and return false
from onDown(...)
than the other methods of GestureDetector.SimpleOnGestureListener
will never get called:
Whether or not you use GestureDetector.OnGestureListener, it's best practice to implement an onDown() method that returns true. This is because all gestures begin with an onDown() message. If you return false from onDown(), as GestureDetector.SimpleOnGestureListener does by default, the system assumes that you want to ignore the rest of the gesture, and the other methods of GestureDetector.OnGestureListener never get called. This has the potential to cause unexpected problems in your app. The only time you should return false from onDown() is if you truly want to ignore an entire gesture.
However, in my simple test onScroll(...)
is been called.
public void onCreate(Bundle savedInstanceState) {
mDetector = new GestureDetectorCompat(this, MyGestureListener);
}
public boolean onTouchEvent(MotionEvent event) {
mDetector.onTouchEvent(event);
return true;
}
class MyGestureListener extends GestureDetector.SimpleOnGestureListener {
private boolean scrollEvent;
@Override
public boolean onDown (MotionEvent event) {
Log.v("GESTURE", "onDown ");
return false;
}
@Override
public boolean onScroll (MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.v("GESTURE", "onScroll");
return true;
}
Another similar issue is the next definition, again from the same android training page:
a return value of true from the individual on methods indicates that you have handled the touch event. A return value of false passes events down through the view stack until the touch has been successfully handled.
How does this settle with the previous quotation?
false
fromonDown(...)
andonScroll(...)
is been called. Thanks for the good answer. – Fessler