11

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.

Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
Ersen Osman
  • 7,067
  • 8
  • 47
  • 80

2 Answers2

2

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);
}
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
1

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;
}
blueware
  • 5,205
  • 1
  • 40
  • 60
  • 1
    Hi, sorry for the late reply. I tried the code but it did not work. I can still only single tap an item. I will post some code soon – Ersen Osman Jun 09 '15 at 11:47