1

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.

Devon Smith
  • 387
  • 1
  • 6
  • 20
  • 1
    well most probably your action_down changes to longClick when pressed for a long time, and since your long click isnt being listened, no actions are performed and action_up is executed...try implementing the longClick listener...might help. – Urban Sep 12 '11 at 19:02
  • I think what you're seeing is this: http://stackoverflow.com/questions/4168687/ontouchlistener-action-up-fires-automatically-after-30-second-timeout but unfortunately there's no workaround... – Mr. Bungle Nov 03 '14 at 11:45

1 Answers1

1

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");
    }
}
prijatev
  • 11
  • 1