Book Image

Android Studio 2 Essentials - Second Edition

By : Belén Cruz Zapata
Book Image

Android Studio 2 Essentials - Second Edition

By: Belén Cruz Zapata

Overview of this book

Android Studio 2, the official IDE for Android application development, dramatically improves your workflow by letting you quickly see changes running on your device or emulator. It gives developers a unique platform by making app builds and deployment faster. This book will get you up and running with all the essential features of Android Studio 2 to optimize your development workflow. Starting off with the basic installation and configuration of Android Studio 2, this book will help you build a new project by showing you how to create a custom launcher icon and guiding you to choose your project. You will then gain an insight into the additional tools provided in Android Studio, namely the Software Development Kit (SDK) Manager, Android Virtual Device (AVD) Manager, and Javadoc. You’ll also see how to integrate Google Play Services in an Android project. Finally, you’ll become familiar with the Help section in Android Studio, which will enable you to search for support you might require in different scenarios.
Table of Contents (17 chapters)
Android Studio 2 Essentials Second Edition
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

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, use the setOnCreateContextMenu method. The OnCreateContextMenu interface declares the following method to receive the long-click event:

    public abstract void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
  • OnDragListener...