1. Activity Code
PackageCom.tsh.dail;Importandroid.app.Activity;Importandroid.content.Intent;ImportAndroid.net.Uri;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.view.View.OnClickListener;ImportAndroid.widget.Button;ImportAndroid.widget.EditText; Public classMainactivityextendsActivity {@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); //Find the button//Button inherits from TextView inherited from view, parent type cast to subtypeButton bt_dail=(Button) Findviewbyid (R.id.bt_dail); //set the Click event to the button, the parameter is the interface interface type of OnclicklistenerBt_dail.setonclicklistener (NewMyListener ()); } /*** Note that the Onclicklistener interface does not guide the wrong, the view under the *@authorTaoshihan **/ Private classMyListenerImplementsonclicklistener{/*** Call this method when the button is clicked*/@Override Public voidOnClick (View v) {//TODO auto-generated Method Stub//Find input box, inner class call method of external class//edittext inherit from TextView, inherit from viewEditText et_number=(EditText) Findviewbyid (R.id.et_number); //Object-oriented thinkingString number=Et_number.gettext (). toString (); //the idea of loose coupling between components, intentions of what to do, intention to call, what the phone number isIntent intent=NewIntent (); Intent.setaction (Intent.action_call); //URI Type Uniform Resource identifier, URL Uniform Resource Locator URI is URL his fatherIntent.setdata (Uri.parse ("Tel:" +Number )); //Open an interfacestartactivity (Intent); //don't forget to turn on permissions. } }}
2. Layout code
<Relativelayoutxmlns: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:paddingbottom= "@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.tsh.dail.MainActivity" > <!--[android:id= "@+id/my_number" R file add an ID] - <EditTextAndroid:id= "@+id/et_number"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:inputtype= "Phone" > </EditText> <!--[Direct extraction of string ctrl+1] - <!--[The yellow exclamation mark cannot be met, clear the project] - <!--[Layout_alignparentright: Aligns to the right of the parent form] - <!--[android:layout_below= "@id/my_number": Located under this ID control, @idR This ID of the file] - <!--[Name of ID, Button Bt_xxx,edittext et_xxx] - <ButtonAndroid:id= "@+id/bt_dail"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_alignparentright= "true"Android:layout_below= "@id/et_number"Android:text= "@string/dail" /></Relativelayout>
[Android] Phone Dialer