Wirelessly four ways to read a click Response event (Phone Dialer)

Source: Internet
Author: User

click-to-respond events in Android are mostly response to events with a button, about four ways to respond to Events1,, create an inner class that defines the click event2, create an anonymous inner class that implements the interface directly3,interface for activity implementation of click events (most common cases used)4,4, a click method is bound in the layout file <Button       Android:onclick= "dailbuttonclicked"...../>Some of the code for this process is based on the implementation of a simple phone Dialer
public class Mainactivity extends Activity implements Onclicklistener {private EditText ed_number;            @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);            Load Layout file Setcontentview (r.layout. Activity_main);          Find button bt_dail= (button) this. Findviewbyid (R.id.button1);                       Find text Box ed_number= (EditText) MainActivity.this.findViewById (R.id.et_number);            Register Click event//1 for the button, create an inner class, define the Click event/* Bt_dail.setonclicklistener (New MyListener ()); *///2, the way to create an anonymous inner class /* Bt_dail.setonclicklistener (New Onclicklistener () {@Override Pub                                     LIC void OnClick (View v) {callphone ();          }}); *//* 3, let activity implement the interface of click events (most common cases used) * Bt_dail.setonclicklistener (this); */} 4, in the layout file is bound a click Method public voID dailbuttonclicked (view view) {Callphone (); }
The specific method implementation is shown in the following code:
private void Callphone () {           String number= ed_number.gettext (). toString (). Trim ();             if (textutils. IsEmpty (number)) {                 toast. Maketext (mainactivity.this, "numbers cannot be empty", toast. Length_short). Show ();                  return;             }                         Intent intent= new Intent ();             Intent.setaction (Intent. Action_call);             URI type             intent.setdata (URI. Parse ("Tel:" +number));             StartActivity (intent);     }     Private class MyListener implements onclicklistener{            /            * * button is called when clicked */            @Override            public void OnClick (View v) {                        callphone ();           }                }     @Override public     void OnClick (View v) {            //TODO auto-generated method Stub            callphone ();     }




Four ways to read about click Response Events in Android (Phone Dialer)

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.