© Ted Hagos 2020
T. HagosLearn Android Studio 4https://doi.org/10.1007/978-1-4842-5937-5_7

7. Event Handling

Ted Hagos1 
(1)
Manila, National Capital Region, Philippines
 
What we’ll cover:
  • Listener objects

  • Anonymous inner classes

In the previous chapter, we already did some event handling. The part of the exercise where we incremented the TextView’s value for each button click was an exercise on declarative event handling . To bind a method name to a click event, we simply set a View’s android:onClick attribute to the name of a method in the associated Activity class. This is a low-ceremony and straightforward way to handle events but is limited to the “click” event. When you need to handle events like long clicks or gestures, you need to use event listeners—this ...

Get Learn Android Studio 4: Efficient Java-Based Android Apps 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.