Android contains two sets of event handling mechanisms:
1. Monitoring-based event processing;
2. Callback-based event handling.
Listener-based event handling
The following three types of objects are involved:
1) Event Source: The source of the event, usually a variety of components, such as buttons, windows, etc.
2) Event events: Events encapsulate specific information about specific events that occur on the interface component, and are typically passed through event events objects if the listener needs to get information about events that occur on the interface component.
3) Events Listener Event Listener: Responsible for listening to events from the event source and handling the different events accordingly.
Is the model of the listener event, the key is in the 4th step, the event listener essentially takes the event as parameters to perform different actions.
In real programming, the general thing we need to do is rewrite the various listeners for the component.
Simple examples:
Public classEventqsextendsactivity{@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.main); //get the BN button in the applicationButton bn =(Button) Findviewbyid (R.ID.BN); //binds the event listener to the button. Bn.setonclicklistener (NewMyclicklistener ());//① } //define a listener for a click event classMyclicklistenerImplementsView.onclicklistener {//implement the method that the listener class must implement, which will act as the event handler@Override Public voidOnClick (View v) {EditText txt=(EditText) Findviewbyid (r.id.txt); Txt.settext (The BN button was clicked! "); } }}
Event handling for Android development