Today to introduce to you is a simple edit text box;
Let's take a look at its basic properties:
1.Activity
Public classEdittextactivityextendsActivity {PrivateEditText Nameedittext; PrivateEditText Passwordedittext; PrivateEditText Ageedittext; Privatebutton button;//Edit Text@Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.edit_text); Nameedittext=(EditText) Findviewbyid (R.id.nameedittextid); Passwordedittext=(EditText) Findviewbyid (R.id.passwordedittextid); Ageedittext=(EditText) Findviewbyid (R.id.ageedittextid); Button=(Button) Findviewbyid (R.id.buttonid); Button.setonclicklistener (NewView.onclicklistener () { Public voidOnClick (View v) {//get the name, password, age you enteredString name =Nameedittext.gettext (). toString (). Trim (); String Password=Passwordedittext.gettext (). toString (). Trim (); String agestring=Ageedittext.gettext (). toString (). Trim (); //for prompt MessagesToast.maketext (edittextactivity. This, "Name=" +name+ "\r\npassword=" +password+ "\r\nage=" +agestring, Toast.length_long). Show (); } }); }}
2.xml file:
<?xml version= "1.0" encoding= "Utf-8"?><!--text edit--><linearlayout xmlns:android= "/http/ Schemas.android.com/apk/res/android "Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"android:orientation= "Vertical"android:padding= "5DP" > <TextView android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Name:"android:textsize= "20sp"/> <EditText Android:id= "@+id/nameedittextid"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter name"/> <TextView android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Password:"android:textsize= "20sp"/> <EditText Android:id= "@+id/passwordedittextid"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter password"Android:inputtype= "Textpassword"/> <TextView android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Age:"android:textsize= "20sp"/> <EditText Android:id= "@+id/ageedittextid"Android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:hint= "Please enter age"Android:inputtype= "Number"Android:maxlength= "3"/> <TextView android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Not Editable"android:textsize= "20sp"/> <EditText android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:editable= "false"Android:hint= "The content here cannot be changed"/> <TextView android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"Android:text= "Cannot get focus (nor can edit)"android:textsize= "20sp"/> <EditText android:layout_width= "Match_parent"Android:layout_height= "Wrap_content"android:focusable= "false"Android:hint= "This input box does not get focus"/> <Button Android:id= "@+id/buttonid"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Show user-filled information"/></linearlayout>
3. as follows:
Edit text (EditText)