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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.