Using this
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
Only detects for single tap event i.e. quick tap and release.
If i hold down and then release, onSingleTapUp
is not called.
I am looking for an motion event which is ACTION_UP
after holding down.
I looked at onShowPress
which is called when the user performs a down action but then I was not sure how to detect a ACTION_UP
while in onShowPress
.
Note this is for a recycler view
to click items. At the moment, I can single tap an item which works but if I hold it down and then release, it is not invoked.
android.view.GestureDetector. Detects various gestures and events using the supplied MotionEvent s. The OnGestureListener callback will notify users when a particular motion event has occurred. This class should only be used with MotionEvent s reported via touch (don't use for trackball events).
Detect gestures. Android provides the GestureDetector class for detecting common gestures. Some of the gestures it supports include onDown() , onLongPress() , onFling() , and so on. You can use GestureDetector in conjunction with the onTouchEvent() method described above.
onSingleTapConfirmed. Notified when a single-tap occurs. Unlike OnGestureListener#onSingleTapUp(MotionEvent) , this will only be called after the detector is confident that the user's first tap is not followed by a second tap leading to a double-tap gesture.
onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) Notified of a fling event when it occurs with the initial on down MotionEvent and the matching up MotionEvent . abstract void. onLongPress(MotionEvent e) Notified when a long press occurs with the initial on down MotionEvent that trigged it.
You can subclass your view and override onTouchEvent
. That will let you observe the different actions before the gesture detector handles them.
@Override
public boolean onTouchEvent(MotionEvent e) {
int action = e.getActionMasked();
if (action == MotionEvent.ACTION_UP) {
// do something here
}
return mGestureDetector.onTouchEvent(e);
}
You may try the following in your onSingleTapUp
method:
@Override
public boolean onSingleTapUp(MotionEvent e) {
if(e.getAction() == MotionEvent.ACTION_UP){
// Do what you want
return true;
}
return false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With