GetAction () gives only ACTION_DOWN

For the application that I am writing, I want to trigger a specific action as soon as the user releases his finger from the screen. I realized that I need to check if event.getAction () is ACTION_UP, but all I get from getAction () is ACTION_DOWN. My code is as follows:

menu = new MenuView(this); menu.setBackgroundColor(Color.WHITE); menu.setKeepScreenOn(true); ... setContentView(menu); menu.requestFocus(); ... public class MenuView extends View { ... public MenuView(Context context) { super(context); setFocusable(true); } 

Does anyone know what is causing the problem?

Thanks in advance.

+4
source share
1 answer

make sure onTouch returns true, which tells os that your listener is handling a touch event.

from docs: onTouch () - returns a boolean value indicating whether your listener is using this event. The important thing is that this event can have several actions that follow each other. Thus, if you return false when a downstream event occurs, you indicate that you did not use the event and are also not interested in the subsequent actions of this event. Thus, you will not be called for any other actions in the event, such as a finger gesture, or a possible up action event.

http://developer.android.com/reference/android/view/View.html#onTouchEvent%28android.view.MotionEvent%29

+13
source

All Articles