The introduction of Android User Interface (UI) Event Handling

Android Event Handling (Source Google Images)

When considering the events in your user interface, the approach is to capture the occurrence of a specific object View that interact with the user. Class View provides the means to do so.

The event listener is an interface class See which contain single callback method. Included in the event listener interface is the callback methods below:

onclick ()  From View.OnClickListener. This is called when the user clicks a button or any item.

onLongClick () From View.OnLongClickListener. This is called when the user clicks the long press of a button or other item.

Syntax Examples of Event Handling is applied to the class java.

Button button= (Button) findViewById(;
button.setOnClickListener(new View.OnClickListener() {
           public void onClick(View view) {
             TextView myText = (TextView) findViewById(;
              myText.setText("Challenge 2 Completed !"); 

Source: Master Android (App)

Post Author: Study