Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getAction() gives only ACTION_DOWN

Tags:

java

android

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 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);
    }

Anybody knows what is the reason for the problem?

Thank you in advance.

like image 997
ronash Avatar asked Dec 12 '22 13:12

ronash


1 Answers

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

like image 111
jkhouw1 Avatar answered Jan 06 '23 21:01

jkhouw1