getAction() gives only ACTION_DOWN
For an application I am writing, I want to invoke a certain action once the user lifted his finger off the screen. I understood I need to check if event.getAction() is ACTION_UP, but all I get from getAction() is ACTION_DOWN. My code looks like this:
menu = new MenuVie开发者_JAVA百科w(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);
}
Anybody knows what is the reason for the problem?
Thank you in advance.
make sure onTouch returns true which tells the os your listener handles the touch event.
from the docs: onTouch() - This returns a boolean to indicate whether your listener consumes this event. The important thing is that this event can have multiple actions that follow each other. So, if you return false when the down action event is received, you indicate that you have not consumed the event and are also not interested in subsequent actions from this event. Thus, you will not be called for any other actions within the event, such as a finger gesture, or the eventual up action event.
http://developer.android.com/reference/android/view/View.html#onTouchEvent%28android.view.MotionEvent%29
精彩评论