[Android] Phone Dialer

Source: Internet
Author: User

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

Related Article

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.