Event handling for Android development

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.