First, create an Android project (my version number is 4.4.2), the name of "Phone Dialer", create the time click "Clipart",
Then locate the layout directory in the Res directory, locate the Activity_main.xml or fragment_main.xml, enter or drag the button
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android:paddi ngbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_horizontal_margin" Android: paddingright= "@dimen/activity_horizontal_margin" android:paddingtop= "@dimen/activity_vertical_margin" tools: context= "Com.csdn.www.mainactivity$placeholderfragment" > <edittext android:id= "@+id/edit" Android: Layout_width= "Fill_parent" android:layout_height= "Wrap_content" android:layout_alignparenttop= "true" Android:layout_centerhorizontal= "true" android:layout_margintop= "16DP" android:ems= "ten" Android:input Type= "Phone"/> <button android:id= "@+id/btn_call" android:layout_width= "Wrap_content" Andro id:layout_height= "Wrap_content" android:layout_below= "@+id/edittext1 "android:layout_centerhorizontal=" true "android:layout_margintop=" 125DP "android:text=" @string/call "/></relativelayout>
Finally, in the Java file under src Mainactivity.java
Package Com.csdn.www;import Android.support.v7.app.actionbaractivity;import Android.support.v7.app.ActionBar; Import Android.support.v4.app.fragment;import Android.text.textutils;import Android.content.intent;import Android.net.uri;import Android.os.bundle;import Android.view.layoutinflater;import Android.view.Menu;import Android.view.menuitem;import Android.view.view;import Android.view.view.onclicklistener;import Android.view.viewgroup;import Android.widget.button;import Android.widget.edittext;import android.widget.Toast; Import Android.os.build;public class Mainactivity extends Actionbaractivity {private Button btn;private EditText EditText; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.fragment_main); btn= (Button) This.findviewbyid (R.id.btn_call); edittext= (EditText) This.findviewbyid (R.id.edit); Btn.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick (View v) {//. Trim () to prevent a space inside string Number=edittExt.gettext (). toString (). Trim (); If the text is empty, it displays the error if (Textutils.isempty (number)) {Toast.maketext (mainactivity.this, "numbers cannot be empty", Toast.length_short). Show (); Return }//intends to do something intent intent=new intent ();//Call Actionintent.setaction (intent. Action_call);//uriintent.setdata (Uri.parse ("Tel:::" +number)); StartActivity (intent);});} @Overridepublic boolean Oncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main, menu); return true;}}
Write to execute at this time, you will find the "Stopped execution" error appears, at this point, you should resolve:
Locate the folder under the Androidmanifest.xml file, open it,
Then you can call!!!