Android ACTION_UP even never called

冷暖自知 提交于 2019-12-10 14:16:57

问题


I'm trying to make a small android Jump and Run game but my problem is that i can't configure the event ACTION_UP right. Here my Code:

public boolean onTouchEvent(MotionEvent event) {
    switch(event.getAction()){
    case MotionEvent.ACTION_DOWN:
        Log.d("OTE", "down"); 
        touchDownTrue = true;
        break;
    case MotionEvent.ACTION_UP:
        Log.d("OTE", "UP"); 
        touchDownTrue = false;
        break;
    }
}

the case MotionEvent.ACTION_UP is never called and i don't know why, the same happens if i use ACTION_CANCEL


回答1:


After I insert return super.onTouchEvent(event); at the end of the method (onTouchEvent must return a value) your code works for me, when I put it in a blank main activity.

You should probably return true instead of breaking in those cases because you are responding to the event.



来源:https://stackoverflow.com/questions/7880284/android-action-up-even-never-called

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!