Delete, make a phone call, send a text message dialog box

Source: Internet
Author: User
Tags lenovo

1-kehoutiactivity.java

Package Com.example.lenovo.textapp4;import Android.app.alertdialog;import Android.content.dialoginterface;import Android.content.intent;import Android.net.uri;import Android.support.v7.app.appcompatactivity;import Android.os.bundle;import Android.view.view;import Android.widget.edittext;import Android.widget.Toast;public class    Kehoutiactivity extends Appcompatactivity {EditText et_1;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);    Setcontentview (R.layout.activity_kehouti); The public void bt_1 (View v) {alertdialog-alertdialog=new alertdialog.builder (this). Settitle (" Prompt "). Setmessage (" OK to delete? \ n to delete, tap yes "). Setpositivebutton (" Yes ", new Dialoginterface.onclickl                        Istener () {@Override public void OnClick (Dialoginterface dialog, int which) { Toast.maketext (Kehoutiactivity.this, "deleted", Toast.length_shoRT). Show (); }}). Setnegativebutton ("No", new Dialoginterface.onclicklistener () {@Ove Rride public void OnClick (Dialoginterface dialog, int which) {Toast.maketext (Ke                    Houtiactivity.this, "not deleted", Toast.length_short). Show ();    }}). Show ();        public void Bt_2 (View v) {Final View view=view.inflate (this, r.layout.shurudianhuahaoma, null);        et_1= (EditText) View.findviewbyid (r.id.et_1);    New Alertdialog.builder (this). Settitle ("Please enter a phone number"). Setview (view). Show ();        Public String Getphone () {string Phone=et_1.gettext (). toString (). Trim (); if (Phone.trim (). Length () ==0) {Toast.maketext (kehoutiactivity.this, "Please fill in the correct phone number", toast.length_short). Sh            ow ();        return null;    } return phone; } public void Bt_11 (View v)    {String phone=getphone ();        if (phone==null) return;        Intent intent=new Intent (intent.action_dial);        Uri Uri=uri.parse ("Tel:" + phone);        Intent.setdata (URI);    StartActivity (Intent);        Public String GetMessage () {String message = Et_1.gettext (). toString (). Trim ();             if (Message.length () ==0) {Toast.maketext (kehoutiactivity.this, "Please fill in the correct phone number", Toast.length_short). Show ();        return null;    } return message;          public void bt_22 (View v) {String message = GetMessage ();          if (message = = null) return;          Uri Smstouri = Uri.parse ("Smsto:message");         Intent Intent = new Intent (intent.action_sendto, Smstouri);         Intent.setdata (Uri.parse ("Smsto:" +message));    StartActivity (Intent); }}
View Code

2-activity_kehouti.xml

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns: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.example.lenovo.textapp4.KehoutiActivity"android:orientation= "vertical">    <ButtonAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Delete"Android:onclick= "Bt_1"/>    <ButtonAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Jump"Android:onclick= "Bt_2"/></LinearLayout>
View Code

3-shuruhaoma.xml

<?XML version= "1.0" encoding= "Utf-8"?><LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent">    <EditTextAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:id= "@+id/et_1"Android:inputtype= "Phone"/>    <LinearLayoutAndroid:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:orientation= "Horizontal">        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "Outgoing call to this number"Android:onclick= "Bt_11"/>        <ButtonAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:layout_weight= "1"Android:text= "Send SMS to this number"Android:onclick= "Bt_22"/>    </LinearLayout></LinearLayout>
View Code

Results

Delete, make a phone call, send a text message dialog box

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.