[Android] 3, EditText use small program

Source: Internet
Author: User
Tags gettext

Here is a simple, look at the following code to know: The button click event with the string str = Et.gettext (). toString (); Gets the text content.

1  Public classMainactivityextendsActivityImplementsonclicklistener{2       PrivateEditText et;//Create a text-edited object3       PrivateButton btn;4       PrivateTextView TV;5 @Override6      Public voidonCreate (Bundle savedinstancestate) {7         Super. OnCreate (savedinstancestate);8 Setcontentview (r.layout.main);9et= (EditText) Findviewbyid (r.id.et);//instantiating text editsTenbtn=(Button) Findviewbyid (R.ID.BTN); OneBtn.setonclicklistener ( This); ATV =(TextView) Findviewbyid (r.id.tv); -     } - @Override the      Public voidOnClick (View v) { -         if(v==btn) { -             //get the text content in EditText -String str =Et.gettext (). toString (); +             //let TextView get to the EditText content str show up - Tv.settext (str); +         }  A     } at}

Note: from the above effect can be seen in the input box is the password type, see the XML file know: 18 Line Password property is true.

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"3 android:orientation= "vertical"4 Android:layout_width= "Fill_parent"5 Android:layout_height= "Fill_parent"6     >7     <TextView8         Android:layout_width= "Fill_parent" 9 Android:layout_height= "Wrap_content" Ten Android:text= "@string/hello" One Android:id= "@+id/tv" A         /> -      <EditText -         Android:layout_width= "Fill_parent"  the Android:layout_height= "Wrap_content"  - Android:hint= "prompt Message" - Android:id= "@+id/et" - Android:password= "true" +      /> -      <Button +         Android:layout_width= "Fill_parent"  A Android:layout_height= "Wrap_content"  at Android:text= "Get edittext content!" - Android:id= "@+id/btn" -         /> - </LinearLayout>

This article link: http://www.cnblogs.com/zjutlitao/p/4229742.html

More Highlights: Http://www.cnblogs.com/zjutlitao

[Android] 3, EditText use small program

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.