LongPress-Detection with GestureDetector doesn't work

721 views Asked by At

I am trying to catch a LongPress-Gesture in my Android App, but the this.gestureDetector.onTouchEvent(event) returns always false. I get the "Longpress detected" in LogCat, but onTouchEvent always return false - any ideas what's wrong here?

final GestureDetector gestureDetector = new GestureDetector(this.getContext(),
            new GestureDetector.SimpleOnGestureListener() {
                @Override
                public void onLongPress(MotionEvent event) {
                    Log.e(TAG, "Longpress detected");
               }
            });

@Override
public boolean onTouchEvent(MotionEvent event) {

    boolean test = this.gestureDetector.onTouchEvent(event);
    Log.v(TAG, Boolean.toString(test)); // test is _always_ false
    if (test) {
       // Do something
        return test;
    }
    return super.onTouchEvent(event);
}
1

There are 1 answers

1
nilo de roock On

Because onLongPress has no return value, it is defined void.

 public void onLongPress(MotionEvent event) {
                     Log.e(TAG, "Longpress detected");
                }