Last active
March 21, 2017 01:06
-
-
Save tcw165/84629d3e2e71d1ce2e57d72cfc5537d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void cancelChildrenTouchEvent(MotionEvent event) { | |
// MotionEvent.obtain creates a new MotionEvent`, copying from an existing one. | |
final MotionEvent canceledEvent = MotionEvent.obtain(event); | |
// The event was handled by the certain child view. In order to make the touch event | |
// lifecycle complete, we have to fake a ACTION_CANCEL for the child view. | |
// Otherwise, it would be chaos. | |
canceledEvent.setAction(MotionEvent.ACTION_CANCEL); | |
super.dispatchTouchEvent(canceledEvent); | |
canceledEvent.recycle(); | |
// Fake our touch event for the same reason. | |
event.setAction(MotionEvent.ACTION_DOWN); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment