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); }
Try code below to detect touch events. mView. setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { //show dialog here return false; } }); To show dialog use Activity method showDialog(int).
onTouch. Added in API level 1. public abstract boolean onTouch (View v, MotionEvent event) Called when a touch event is dispatched to a view. This allows listeners to get a chance to respond before the target view.
Use btn. setEnabled(false) to temporarily disable it and then btn. setEnabled(true) to enable it again.
The touch event is passed in as a MotionEvent , which contains the x,y coordinates, time, type of event, and other information. The touch event is sent to the Window's superDispatchTouchEvent() . Window is an abstract class.
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; } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With