Android from ignorance to knowledge-No. 2 and androidno. 2

Source: Internet
Author: User

Android from ignorance to knowledge-No. 2 and androidno. 2

Despite encountering bottlenecks in the past few days, they are getting better and better. Because they have never touched android before, as a newbie, they will not be overly demanding. Compared with the distributed resource search last year, mobile development this year is actually simpler, although there is no major difference in its nature, but in terms of user experience, it can stimulate the interest of every learner. This may be the charm of android...

When I finally loaded my Phone Dialer to the simulator, I didn't know what went wrong. The system was always turned off automatically, and I was so angry that I didn't talk about it anymore; yesterday I made another "text message sender" and encountered similar problems with the former. However, after debugging, it was developed successfully. Therefore, I adjusted the former and the same solution, hairgood ~~~ Next, let's take the text message sender as an example to talk about some of our learning experiences...

First:

Let's talk about the basic structure of the text message sender. We can also see that it can be divided into five parts: Two prompts + two input boxes, and a send button. Then, let's take a look at the following code:

<EditText        android:id="@+id/et_word"        android:lines="5"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:layout_below="@id/tv_ism"        android:layout_centerVertical="true"        android:inputType="textMultiLine" ></EditText>

This Code defines the text message input box. The "@ + id/et_word" at the top is in R. add an id named et_word in the java file, that is, declare our input box; lines = "5" specifies that the input box is five lines, which can generally meet our needs; the following four layout attributes define the length, width, and relative position of the text box. The attribute values are interesting, the third one means that the text box is located at the bottom of the id TV _ism, and TV _ism is what we see: "Enter the text message content". Finally, the text message input box type is defined. The other several pieces of content are similar to them, and of course there are many attributes. You can check their APIs for details.

The uidesign is relatively simple. I hope you will be able to forgive me. The next step is to give it the corresponding functions, and add a large part of the Code:

Public class MainActivity extends Activity implements OnClickListener {private EditText et_word; private EditText et_number; @ Override protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); et_number = (EditText) findViewById (R. id. et_number); et_word = (EditText) findViewById (R. id. et_word); Button bt_sent = (Button) findViewById (R. id. bt_sent); bt_sent.setOnClickListener (this) ;}@ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. bt_sent: String word = et_word.getText (). toString (). trim (); String number = et_number.getText (). toString (). trim (); if (TextUtils. isEmpty (word) | TextUtils. isEmpty (number) {Toast. makeText (this, "the phone number or text message content cannot be blank", Toast. LENGTH_SHORT ). show (); return;} else {SmsManager smsManager = SmsManager. getDefault (); ArrayList <String> words = smsManager. divideMessage (word); for (String str: words) {smsManager. sendTextMessage (number, null, str, null, null) ;}} break ;}}}

First, we need to find the send button to enable the text message sender to send the text message, but when we click the button, the system will find the text message content and the number to be sent, and then implement its functions, which is roughly divided into these three steps.

Therefore, first find the Button: Button bt_sent = (Button) findViewById (R. id. bt_sent); bt_sent.setOnClickListener (this); this involves several common methods, which can be understood by the user. First, find the button by id and call its method to set the click event; the onClick (View v) below is the implementation method of the OnClickListener interface, and the obtained id is R. id. bt_sent performs a series of operations. The et_number, et_word, and bt_sent above are the same. They are first identified by id, and then their own methods are used to extract the phone number and text message content; the next step is to determine whether the phone number or text message content is empty. I believe everyone has this common sense. If either of them is empty, they cannot send text messages. You can check Toast for details, it is translated into Chinese as "shredded bread". It mainly serves as a reminder that the method called by the user has three parameters, which is not well understood at the beginning. In this example, you can also guess what it means. The third parameter is the display duration. Do not forget to call Toast's show () return value. If the number or content is not empty, execute the statement in else to extract the text message content. If the sent content is too long, if the number of characters exceeds the limit of 70 or 160, ArrayList <String> words = smsManager is used. divideMessage (word); then traverse it, smsManager. sendTextMessage (number, null, str, null, null); there are five parameters, the first is the contact phone number to be sent, and the second is where the text message comes from, currently, Chinese operators do not support this function. The third is the content of the sent text message. The fourth parameter is to report whether the text message is sent successfully. The fifth parameter is whether to send the delivery report, this can be set to null.

Note that SmsManager smsManager = SmsManager. getDefault (); this statement indicates that the default imported package has expired, so you need to import a new package. A prompt will be displayed at that time.
OK, so that a simple text message sender can be set up. Start the two simulators to perform the experiment, as shown in. The differences between short text and long text are also clear at a glance. Today, we will continue to learn more about the four la s and the arrival of the UI era ......
 


Answer: from ignorance to knowledge,

B
 
From ignorance to knowledge, it means not understanding, or being immature to maturity.

From ignorance to ignorance, you can accept some nonsense words with patience.
 

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.