Taking Actions

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 ...

Get Hands-On Android UI Development 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.