MotionEvent.ACTION_UP not called
Also note that under certain circumstances (eg. screen rotations) the gesture may be cancelled, in which case a MotionEvent.ACTION_UP
will NOT be sent. Instead a MotionEvent.ACTION_CANCEL
is sent instead. Therefore a normal action switch statement should look something like this:
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
// check if we want to handle touch events, return true
// else don't handle further touch events, return false
break;
// ... handle other cases
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
// finish handling touch events
// note that these methods won't be called if 'false' was returned
// from any previous events related to the gesture
break;
}
You should return true;
in case MotionEvent.ACTION_DOWN:
, so the MotionEvent.ACTION_UP
will be handled.
As explained on View.OnTouchListener:
Returns:
True if the listener has consumed the event, false otherwise.
MotionEvent.ACTION_UP
Won't get called until the MotionEvent.ACTION_DOWN
occurred, a logical explanation for this is that it's impossible for an ACTION_UP
to occur if an ACTION_DOWN
never occurred before it.
This logic enables the developer to block further events after ACTION_DOWN
.