简体   繁体   中英

Android ACTION_DOWN event automatically executes ACTION_UP event after few seconds

I have created an application in which user have to touch an image for near about 10 sec. So I have registered ACTION_DOWN event. But this event automatically executes ACTION_UP event after few seconds even if user does not take the finger up. Is there any workaround for this problem? Any help will be greatly appreciated.

I'm a java/android noob but here's a code that works for me:

class HelloOnTouchListener implements OnTouchListener {
    public boolean onTouch(View v, MotionEvent e) {
        handleTouchEvent(e);
        return true;
    }
}

public void handleTouchEvent(MotionEvent e) {
    int eAct = e.getAction(); 
    if (eAct == 0) Log.d("touch", "press");
    else if (eAct == 1) Log.d("touch", "release");
}

And here's a code that doesn't (UP fires twice, first right after DOWN and then when you actually release):

public void handleTouchEvent(MotionEvent e) {
    int eAct = e.getAction();
    switch (eAct) {
        case MotionEvent.ACTION_DOWN: Log.d("touch", "press");
        case MotionEvent.ACTION_UP: Log.d("touch", "release");
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM