Implementation steps:
1. Drawing the UI
You can use drag-and-drop and text editing.
2. Write business logic according to UI in OnCreate in Mainactivity
Get EditText Contentet_number = (editText) Findviewbyid (R.ID.EDITTEXT1);//find zhe Buttonbutton btn_call = (Button) Findviewbyid (R.id.button);
3. Set a click event inner class for the button
New MyListener ()); in//oncreate
Private classMyListenerImplementsview.onclicklistener{ Public voidOnClick (View v) {String number=Et_number.gettext (). toString (). Trim (); if("". Equals (number)) {Toast.maketext (mainactivity). This, "Please enter the number you want to dial", Toast.length_short). Show (); return; } Intent Intent=NewIntent (); Intent.setaction (Intent.action_call); Intent.setdata (Uri.parse ("Tel:" +Number )); StartActivity (Intent); } }
4. Set a click event Hide class for the button
Btn_call.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {String number=Et_number.gettext (). toString (). Trim (); if("". Equals (number)) {Toast.maketext (mainactivity). This, "Please enter the number you want to dial", Toast.length_short). Show (); return; } Intent Intent=NewIntent (); Intent.setaction (Intent.action_call); Intent.setdata (Uri.parse ("Tel:" +Number )); StartActivity (Intent); } });
5. Set a click event for the button to implement the interface type in the current class
6. Set a click event for the button
7. Plus the right to call
<uses-permission android:name= "Android.permission.CALL_PHONE"/>
End
Android app Simple Phone Dialer