29

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);
}
AL.
  • 36,815
  • 10
  • 142
  • 281
dinesh707
  • 12,106
  • 22
  • 84
  • 134

4 Answers4

76

You can use 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;
  }
});
ClassA
  • 2,480
  • 1
  • 26
  • 57
Aleadam
  • 40,203
  • 9
  • 86
  • 108
8
public boolean onTouchEvent(MotionEvent event) {
        Log.d(TAG,""+event.getAction());
        return true; // Required for recieving subsequent events (ACTION_MOVE, ACTION_UP)
}
Lamellama
  • 621
  • 6
  • 4
1
view.setOnTouchListener(new OnTouchListener () {
  public boolean onTouch(View view, MotionEvent event) {
        if(event.getAction() == MotionEvent.ACTION_UP) {
            // release
            return false;
        } else if(event.getAction() == MotionEvent.ACTION_DOWN) {
            // pressed
            return true;
        }
        return super.onTouchEvent(event);
    }
Linh
  • 57,942
  • 23
  • 262
  • 279
1

I had the same problem with class SurfaceView. Here's how I fixed it: After enabling your view's long clickable property(through setLongClickable(true)), it should works.

ajacian81
  • 7,419
  • 9
  • 51
  • 64
code0tt
  • 41
  • 8