开发者

Handle OnTouch Event inside an Activity

开发者 https://www.devze.com 2023-02-03 17:42 出处:网络
Im Trying to handle an OnTouch Event inside an activity But I am unable to Handle MotionEvent.ACTION_UP Action. here is my code:

Im Trying to handle an OnTouch Event inside an activity But I am unable to Handle MotionEvent.ACTION_UP Action. here is my code:

boardView.setOnTouchListener(new OnTouchListener() {

        @Ov开发者_运维问答erride
        public boolean onTouch(View v, MotionEvent event) {

            switch (event.getAction())
            {
            case MotionEvent.ACTION_DOWN:
                showToastNotification("ACTION_DOWN");
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                showToastNotification("ACTION_UP");
                break;
            }

            return false;
        }



    });

Why Is That?

Thanks in advance

Kobi


The "onTouch" event has to return "true" istead of "false".


Do you see the "ACTION_DOWN" toast? Is it just the "ACTION_UP" toast which does not show?


Could be (Guess) When ACTION_DOWN happens, the Toast appears and the Activity is not in control of ACTION_UP. Or.. as @C0deAttack said, it might be behind the scenes. Use ACTION_DOWN notification as Toast.short and ACTION_UP as Toast.long .. OR you could use LogCat.

0

精彩评论

暂无评论...
验证码 换一张
取 消