How does Android detect events? I’m not asking about implementing different handlers for events, but the logic on decide the event types. For example, when the user performs a swipe on the screen, where the Android SDK detects that this is a swipe event instead of a scroll event or other events? Thanks in advance!
How does Android detect events? I’m not asking about implementing different handlers for events,
Share
Touch events are typically interpreted by a
GestureDetector. Typically, touch events are handled by aViewby simply passing them to aGestureDetector. TheGestureDetectordetects when there is some particular gesture (tap, fling, etc.) by analyzing the recent history of touch events. TheGestureDetectorthen notifies one of the registered listeners (often a subclass ofSimpleOnGestureListener).It’s up to the listener to decide what the semantic meaning is of the gesture. For instance, a
ScrollViewwill set anOnGestureListenerthat reacts to a fling event by scrolling rapidly. A custom view might react to a fling by deleting some object from the view.