Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Touch Release method in Android

Tags:

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); } 
like image 683
dinesh707 Avatar asked Apr 23 '11 17:04

dinesh707


People also ask

How do I get touch event on android?

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).

What is onTouch Android?

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.

How do I turn off Touch listener on Android?

Use btn. setEnabled(false) to temporarily disable it and then btn. setEnabled(true) to enable it again.

How are Android touch events delivered?

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.


1 Answers

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;   } }); 
like image 172
Aleadam Avatar answered Oct 06 '22 00:10

Aleadam