Android Event Handling

What are events in android?

Events are the messages or notifications which are generated by controls such as buttons, checkbox, radio buttons etc. System responds to those messages or notifications by executing some code.

Following are the three concepts related to Android Event Management,

1. Event Listener contains a single callback method. It is an interface in the View class.
2. Event Handler is the method that handles the event. The Event Listener calls the Event Handlers.
3. Event Listener Registration is a process, where an Event Handler gets registered with an Event Listener. Event Handler is called when the Event Listener fires the event.

Following are the Event Handlers and Event Listeners that handle the user's interaction with interactive components of Application

Event HandlerEvent ListenerDescription
onClick()OnClickListener()Called when the user either clicks or touches any widget like button, images, text etc.
onLongClick()OnLongClickListener()Called when the user either clicks or touches any widget like button, text, image etc. for one or more seconds.
onFocusChange()OnFocusChangeListener()Called when the widget looses its focus that means the user goes away from the view point.
onKey()OnFocusChangeListener()Called when the user is focused on the item and presses or releases a key on the device.
onTouch()OnTouchListener()Called when the user presses or releases the key.
onMenuItemClick()OnMenuItemClickListener()Called when the user selects a menu item.
OnCreateContextMenu()OnCreateContextMenuITemListener()Called when the context menu is being built.