6.3.4. Overriding View Method onTouchEvent

Users interact with this app by touching the device’s screen. A touch aligns the cannon to face the touch point on the screen, then fires the cannon. To process simple touch events for the CannonView, you’ll override View method onTouchEvent (Section 6.8.13), then use constants from class MotionEvent (package android.view) to test which type of event occurred and process it accordingly.

Get Android™ How to Program, Second 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.