Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What causes a MotionEvent.ACTION_CANCEL in Android?

I am working through debugging some touch handling stuff on Android, and am trying to figure out why the MotionEvent sent to my View's onTouchListener contains a cancel action. I have not been able to find any documentation on its cause, and was hoping someone could point me in the right direction for debugging this problem - error codes, source code, or some general knowledge.

like image 769
Phil Avatar asked Aug 14 '12 21:08

Phil


Video Answer


2 Answers

Is this what you are looking for:

"ACTION_CANCEL occurs when the parent takes possession of the motion, for example when the user has dragged enough across a list view that it will start scrolling instead of letting you press the buttons inside of it. You can find out more about it at the viewgroup documentation: onInterceptTouchEvent."

Hope that is the answer you are looking for:

Resources: Motion Event, Stack Overflow.

like image 74
0gravity Avatar answered Sep 26 '22 01:09

0gravity


All you need is to call

requestDisallowInterceptTouchEvent(true); 

on the parent view, like this -

        @Override         public boolean onTouch(View view, MotionEvent motionEvent) {             view.getParent().requestDisallowInterceptTouchEvent(true);             switch(motionEvent.getActio){             }              return false;            } 

Source: onInterceptTouchEvent, onTouchEvent only see ACTION_DOWN

like image 20
Marc Alexander Avatar answered Sep 26 '22 01:09

Marc Alexander