Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I registered a listener to a RelativeLayout, see below. I'd like to add some custom 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?

like image 678
fifth Avatar asked May 09 '11 06:05

fifth


1 Answers

"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.

like image 108
LeffelMania Avatar answered Nov 16 '22 02:11

LeffelMania