GestureDetector.SimpleOnGestureListener. How do I detect an ACTION_UP event?

2.7k views Asked by At

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.

2

There are 2 answers

1
blueware On

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;
}
0
Suragch On

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);
}