© Ted Hagos 2018
Ted HagosLearn Android Studio 3 https://doi.org/10.1007/978-1-4842-3156-2_5

5. Handling Events

Ted Hagos1 
(1)
Manila, National Capital Region, Philippines
 

Event handling is basically just writing program logic in response to a user action. This program logic is written usually as part of Java methods. There are two ways you can handle events: you can do it either declaratively or programmatically. This chapter explores both ways.

Overview of Event Handling

The process of handling events declaratively can be broken down as follows.
  1. 1.

    Define the view object (e.g., a Button view). This can be done in either design or text mode

    <Button
      android:id="@+id/button"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content" ...

Get Learn Android Studio 3: Efficient Android App 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.