开发者

Android: can't see ACTION_MOVE/UP in onTouchEvent of a RelativeLayout

开发者 https://www.devze.com 2023-03-04 01:47 出处:网络
I registered a listener to a RelativeLayout, see below. I\'d like to add some cus开发者_Python百科tom event handling,

I registered a listener to a RelativeLayout, see below. I'd like to add some cus开发者_Python百科tom event handling,

mOnTouchListener = new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            final int action = motionEvent.getAction();
            boolean ret = false;

            switch (action) {
            case MotionEvent.ACTION_DOWN:
                ret = doSth(motionEvent);
                break;
            case MotionEvent.ACTION_MOVE:
                ret = doSth(motionEvent);
                break;
            case MotionEvent.ACTION_UP:
                ret = doSth(motionEvent);
                break;
            }

            return ret;     // returning false got me none of MOVE/UP events right here
        }
    };

However, I can't get any MOVE/UP events unless returned true.

Another try, I registered same listener to a CheckBox, everything went quite well.

Is there difference between ViewGroup and Widget? Design purpose?


"However, I can't get any MOVE/UP events unless returned true."

You've answered your own question. If you don't return true indicating that you care about and are handling the event, the system will not send you the subsequent events, because you've told the system you don't care about it. If you need to monitor the entire life cycle of the touch event, you need to return true always.

0

精彩评论

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