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 thesetOnClickListener
method. TheOnClickListener
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 thesetOnCreateContextMenu
method. TheOnCreateContextMenu
interface declares the following method to receive the long-click event:public abstract void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo)
OnDragListener...