GestureDetector.SimpleOnGestureListener. How do I detect an ACTION_UP event?
Asked Answered
B

2

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.

Benefactor answered 7/6, 2015 at 11:57 Comment(2)
Have you solved your issue?Remodel
@Remodel Hi, I did not solve this particular issue but used a different solution altogether to solve my problem which was to set a OnClickListener on the itemView itself.Benefactor
M
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);
}
Mandarin answered 17/1, 2018 at 22:18 Comment(0)
P
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;
}
Precincts answered 7/6, 2015 at 12:8 Comment(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 soonBenefactor

© 2022 - 2024 — McMap. All rights reserved.