Handling events is an essential part of any application; they are the raw input data for a user interface and how we interact with our users (rather than just presenting them with data). Android has an event model that will be instantly familiar to anyone who has programmed Java on their desktop--you attach listener objects to the widgets, and they deliver events to you.
Event listeners in Android take the form of interfaces that you need to implement in order to receive the events. Each possible event type is declared as a method on the relevant interface. To receive a notification that the user has clicked or tapped on a widget, you use the OnClickListener interface, which declares a method--onClick(View)--which will be invoked when the relevant widget receives what it considers a click gesture from the user.
In this chapter, we'll take a look at events on...