Predict the output
A custom view returns false from onTouchEvent for ACTION_DOWN. What happens to the following ACTION_MOVE events?
class Knob(context: Context) : View(context) {
override fun onTouchEvent(event: MotionEvent): Boolean {
if (event.actionMasked == MotionEvent.ACTION_MOVE) log("moved")
return false
}
}Hint 1 of 1
Who receives the rest of a gesture?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A They never reach the view; 'moved' is never logged
Correct. Not claiming ACTION_DOWN means the view isn't the target for the rest of the gesture.
Why not the others?
- B They arrive and 'moved' is logged. Only the view that consumed DOWN gets the following events.
- C They arrive as ACTION_CANCEL. CANCEL is sent when a parent steals a gesture you already own.
- D The app crashes. Returning false is allowed.