Explain touch event dispatch in a ViewGroup with a clickable child

It tests touch routing through the three key methods. A strong answer traces ACTION_DOWN from root to target, notes intercepting halts child delivery, and onTouchEvent true consumes while false bubbles up.
WHAT THIS TESTS: This question probes whether you understand the contract between dispatchTouchEvent, onInterceptTouchEvent, and onTouchEvent inside Android's view hierarchy. Interviewers care if you can predict event flow when a parent ViewGroup contains a clickable child View, because mishandling this breaks gestures, scrolling, and nested interactions.
A GOOD ANSWER COVERS: First, the entry point is dispatchTouchEvent on the root view, which traverses down the hierarchy. Second, a ViewGroup gets a chance to observe or steal the event in onInterceptTouchEvent before the child sees it. Third, if the parent does not intercept, the event reaches the child's dispatchTouchEvent and then its onTouchEvent. Fourth, if the child returns true from onTouchEvent, it claims the event stream for the remainder of the gesture, meaning subsequent ACTION_MOVE and ACTION_UP events flow to the child unless the parent intercepts mid gesture. Fifth, if the child returns false, the event bubbles back up to the parent's onTouchEvent. Sixth, returning true from onInterceptTouchEvent during ACTION_DOWN prevents the child from ever receiving that gesture, while intercepting later during ACTION_MOVE sends ACTION_CANCEL to the child and redirects future events to the parent's onTouchEvent.
COMMON WRONG ANSWERS: A red flag is claiming that onInterceptTouchEvent exists on View instead of ViewGroup. Another mistake is saying the parent always receives onTouchEvent before the child, when actually the child gets the first shot if the parent does not intercept. Some candidates also forget that intercepting after ACTION_DOWN sends ACTION_CANCEL to the child, which leads to broken touch states in custom views.
LIKELY FOLLOW UPS: The interviewer may ask how nested scrolling changes this flow, or how requestDisallowInterceptTouchEvent allows a child to prevent its parent from intercepting. They might also ask you to debug a scenario where a ListView inside a ScrollView fights over vertical swipes, or how to implement a custom ViewGroup that only intercepts horizontal drags while letting vertical taps pass to a child button.
ONE CONCRETE EXAMPLE: Imagine a FrameGroup containing a Button. When the user presses the button, the FrameGroup's dispatchTouchEvent receives ACTION_DOWN. The FrameGroup's onInterceptTouchEvent runs and returns false, so the event travels to the Button. The Button's onTouchEvent returns true because it is clickable, consuming the ACTION_DOWN. The framework now marks the Button as the target for this pointer. On ACTION_UP, the event again enters through the FrameGroup's dispatchTouchEvent, skips onInterceptTouchEvent unless the parent explicitly requests it, and reaches the Button's onTouchEvent to fire the click. If the FrameGroup instead returned true from onInterceptTouchEvent during ACTION_MOVE, the Button would receive ACTION_CANCEL, and all remaining events would go to the FrameGroup's onTouchEvent.
Source: developer.android.com
Read the original → developer.android.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.