Android (3)

Source: Internet
Author: User
Tags gettext

1. Telephone Dialer:

Activity_main.xml

<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= ". Mainactivity "> <edittext android:id=" @+id/edittext1 "android:layout_width=" Match_parent "and roid:layout_height= "Wrap_content" android:inputtype= "Phone" > </EditText> <button android:id = "@+id/button1" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" Android:layout_ Alignparentright= "true" android:layout_below= "@+id/edittext1" android:text= "call"/>//Note: If you want this XML file to have no exclamation marks, Need to be configured in Strings.xml </RelativeLayout>


Mainactivity.java

Package Com.csdn.duil;import Android.net.uri;import Android.os.bundle;import android.app.activity;import Android.content.intent;import Android.text.inputfilter.lengthfilter;import Android.text.textutils;import Android.view.menu;import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.Button; Import Android.widget.edittext;import Android.widget.toast;public class Mainactivity extends Activity {/** * Click event method * 1. Chong    Build an inner class to define the click event * 2. Create a Click event with an anonymous inner class * 3. Methods not implemented in the interface (this) common * 4. In the layout file, bind a click Method */private Button btn;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Load Layout file Setcontentview (r.layout.activity_main);        Find the button btn= (buttons) This.findviewbyid (R.id.button1); Btn.setonclicklistener (New Onclicklistener () {@Overridepublic void OnClick (View arg0) {EditText text= (EditText) MainActivity.this.findViewById (R.ID.EDITTEXT1);//Gets the text to go to the space String Number=text.gettext (). ToString (). Trim (); Determines if number is empty if (Textutils.isempty ()) {Toast.maketext (mainactivity.this, "numbers cannot be empty", toast.length_short). Show    ();    Return    }//intention to do one thing Intent intent=new Intent ();    Beating Intent.setaction (Intent.action_call);        URL Uniform Resource Locator Uri is more powerful, Uniform Resource Identifier Intent.setdata (Uri.parse ("Tel:" +number));    StartActivity (intent);}}); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to the Actio        n Bar if it is present.        Getmenuinflater (). Inflate (R.menu.main, menu);    return true; }    }



2. Short Transmitters:

Activity_main.xml

<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= ". Mainactivity "> <button android:id=" @+id/button1 "android:layout_width=" Wrap_content "Androi d:layout_height= "Wrap_content" android:layout_alignleft= "@+id/edittext2" android:layout_below= "@+id/editText 2 "android:layout_margintop=" 21DP "android:text=" send "/> <textview android:id=" @+id/textview1 "Android:layout_width=" wrap_content "android:layout_height=" Wrap_content "android:layout_alignleft=" @+id/edittext1 "Android:layout_alignparenttop= "true" android:text= "@string/please_input_number" android:textappearance= "? Android:attr/textappearancelarge "/> <edittext android:id=" @+id/edittext1 "android:layout_width=" Match_parent "android:layou t_height= "Wrap_content" android:layout_alignparentleft= "true" android:layout_below= "@+id/textview1" a        ndroid:layout_margintop= "23DP" android:ems= "ten"/> <textview android:id= "@+id/textview2" Android:layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_alignleft= "@+id/ed ItText1 "android:layout_alignright=" @+id/edittext1 "android:layout_below=" @+id/edittext1 "Android:lay        out_margintop= "25DP" android:text= "Please enter the content" android:textappearance= "? Android:attr/textappearancelarge" Android:textcolor= "#ff0000"/> <edittext android:lines= "5" android:id= "@+id/edittext2" Andro Id:layout_width= "Fill_paRent "android:layout_height=" wrap_content "android:layout_alignparentleft=" true "Android:layout_below = "@+id/textview2" android:layout_margintop= "25DP" android:ems= "android:inputtype=" Textmultiline " > <requestfocus/> </EditText></RelativeLayout>


Mainactivity.java

Package Com.csdn.sms;import Java.util.arraylist;import Android.os.bundle;import android.app.activity;import Android.telephony.smsmanager;import Android.text.textutils;import Android.view.menu;import Android.view.View; Import Android.view.view.onclicklistener;import Android.widget.button;import Android.widget.edittext;import    Android.widget.toast;public class Mainactivity extends Activity implements Onclicklistener {private Button btn_send;    Private EditText Text1;    Private EditText Text2;        @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);        Setcontentview (R.layout.activity_main);        text1= (EditText) This.findviewbyid (R.ID.EDITTEXT1);                Text2= (EditText) This.findviewbyid (R.ID.EDITTEXT2);        Btn_send= (Button) This.findviewbyid (R.id.button1);    Btn_send.setonclicklistener (this); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {//Inflate the menu, this adds items to The Action Bar if it is present.        Getmenuinflater (). Inflate (R.menu.main, menu);    return true; } @Overridepublic void OnClick (View v) {switch (V.getid ()) {case r.id.button1:string number=text1.gettext (). toString (). Trim (); String Context=text2.gettext (). toString (). Trim (); if (Textutils.isempty (context) | | Textutils.isempty (number)) {Toast.maketext (this, "phone numbers or content cannot be empty", Toast.length_short). Show (); return;} Else{smsmanager Smsmanager=smsmanager.getdefault ();//MMS//smsmanager.sendtextmessage (number,null, context, NULL, NULL);//Send multiple SMS arraylist<string> contents=smsmanager.dividemessage (context); for (String str:contents) { Smsmanager.sendtextmessage (number,null, str, NULL, NULL);}}    Break;default:break;}} }


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.