O'Reilly logo

Android Studio 2 Essentials - Second Edition by Belén Cruz Zapata

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Handling events

The user interface would be useless if the rest of the application could not interact with it. Events in Android are generated when the user interacts with our application. All the UI widgets are children of the View class, and they share some events handled by the following listeners:

  • OnClickListener: This captures the event when the user clicks on the view element. To configure this listener in a view, use the setOnClickListener method. The OnClickListener interface declares the following method to receive the click event:
    public abstract void onClick(View v)
  • OnCreateContextMenu: This captures the event when the user performs a long click on the view element and we want to open a context menu. To configure this listener in a view, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required