Creating Button Event Handlers
To make the buttons do something, you need to add event handlers to the buttons that detect when they are clicked, and you need to supply the method to be called. There are several ways of doing this with the Android SDK, but first let’s take the simple approach and add the handlers to the layout.
1. Open the activity_timer.xml
layout file, and locate the two buttons you added earlier. Add the two click handlers to the appropriate buttons by setting android:onClick
to the name of the methods you want called when the buttons are clicked. Call the two methods clickedStart
and clickedStop
, as shown in Listing 4.3.
<Button android:id ...
Get Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications 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.