How to stop receiving onTouchEvents for gestures after returning for the first time

I know that for an Android view, if I go back truein onTouchEvent, it means that you want to keep receiving events for the current gesture. If you return false, he should not process more events for the current gesture

However, I would like to try to determine if the gesture is a click or hold / drag event, so I return trueto the initial event ACTION_DOWNuntil a few milliseconds expire, and at that moment I time out and recognize the gesture as a hold / drag and not a click .

As soon as the timeout expires, I would like to return falsefor further onTouchEvents so that I can stop accepting events and let the parent view control the rest of the drag and drop.

However, I seem to notice that as soon as you return truefor the first event, it receives all further events with an appropriate gesture, even after I constantly return falseto later events. It seems that the return value only matters for the very first event, after which it is ignored.

Is there a way to stop receiving onTouchEventand therefore pass it to the parent as soon as you accept the first event in the gesture?

+3
source share
1 answer

, onTouchEvent , - , .

, , :

private boolean hasHandledGesture = false;

public boolean onTouchEvent( MotionEvent event ){

    if( !hasHandledGesture ){
        // Do your actual handling here for the first event
        return true;
    } else {
        return super.onTouchEvent( event );
    }
}

, , setOnLongClickListener. , OS , , . , , , .

, GestureDetector, , , , .

+2