Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

8. Handling Gestures > Listening to Touch Events

Listening to Touch Events

The most basic form of gesture recognition is the touch event. Touch events are the lowest level of user interaction with the touchscreen. Events include putting a finger on the screen, sliding a finger along the screen, and lifting a finger off the screen. Each of these represents a discrete touch event. There are two ways you can listen for these events: by registering an OnTouchListener on a view and implementing the onTouchEvent method, or by implementing your own view and overriding its onTouchEvent method. These methods are called with a MotionEvent object containing information about the event.

Here is a simple example class that overrides View and implements the onTouchEvent method:

1. Create a class named TouchExample that extends View:


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial