For the More Curious: GestureDetector

Another option for handling touch events is to use a GestureDetector object. Instead of adding logic to detect events like a swipe or a fling, the GestureDetector has listeners that do the heavy lifting and notify you when a particular event occurs. The GestureDetector.OnGestureListener implementation has functions for events such as long presses, flings, and scrolls. There is also a GestureDetector.OnDoubleTapListener that will fire when a double-press is detected. Many cases do not require the full control provided by overriding the onTouch function, so using the GestureDetector instead is a great choice.

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.