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?
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With