: The core principle of telephone dialer: Intent mainactivity Code: Private Edittest et_number;//loading a layout setcontentview (R.layout.main); //gets the desired control editTest1 Button1 et_number = (edittest) Findviewbyid (r.id.edittest1); button Btn_call = ( button) Findviewbyid (r.id.button1) //for button Btn_call set Click events Implement an inner class Btn_call.setonclicklistener (new Myclicklistener ()); //Inner class implement Click event Private class Myclicklistener (View v) { String number = et _number.gettext (). toString (). Trim (); if ("". Equals (number)) { Toast.maketest (Mainactivity.this, "mobile phone number cannot be empty! ", Length_long);} //Create an intent Intent Intent = new Intent (); / /Set Intent action intent.setaction (intent.action_call); //Set Intent data Intent.setdata (Uri.parse ("Tel:" +number); //Open Intent startactivity (intent);} Summary: 1. Intent: First step: Create intent intent Intent = new Intent (); second step: Set action Intent.setaction (string); step three: Set Object Intent.setdata ( Path); Fourth step: Open Intent startactivity (intent); 2. Four ways to implement the Click event:
- Inner class
Btn_call.setonclicklistener (interface type new Myclicklistener ());
Private Class Myclicklistener (View v) {
Callphone ();
}
- Anonymous inner class
Btn_call.setonclicklistener (New Onclicklistener (View v) {
Implement the OnClick () method that is not implemented in the Onclicklistener class
- Mainactivity implementation of Onclicklistener-------------for multiple buttons
Btn_call1.setonclicklistener (this);
Btn_call2.setonclicklistener (this);
Btn_call3.setonclicklistener (this);
Switch (V.getid ()) ....
- Write a class with the same name as the Click Property. Implement click events in this class
Android Case one Phone Dialer