dinesh707 dinesh707 - 24 days ago 7
Android Question

Touch Release method in Android

I'm trying to capture the

TouchRelease
event in Android. I have seen that
event.getAction()
returns the action type. But inside
onTouchEvent
it always gives the action
ACTION_DOWN
.

Do you know how to capture the touch release event.

public boolean onTouchEvent(MotionEvent event) {
Log.d(TAG,""+event.getAction());
return super.onTouchEvent(event);
}

Answer

You have ACTION_UP: http://developer.android.com/reference/android/view/MotionEvent.html#ACTION_UP

View view = new View();

view.setOnTouchListener(new OnTouchListener () {
  public boolean onTouch(View view, MotionEvent event) {
    if (event.getAction() == android.view.MotionEvent.ACTION_DOWN) {
      Log.d("TouchTest", "Touch down");
    } else if (event.getAction() == android.view.MotionEvent.ACTION_UP) {
      Log.d("TouchTest", "Touch up");
    }
    return true;
  }
}