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