Android Common UI Components-EditText

Source: Internet
Author: User

EditText is the most important Android UI component that accepts user input information and can take advantage of edittext.gettext () to get its text content.

Example: Edittextdemo
Operating effect:

Code Listing:
Layout file: Main.xml
<?xml version= "1.0" encoding= "Utf-8"? ><tablelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Fill_parent "android:layout_height=" Fill_parent "android:stretchcolumns=" 1 "    ; <TableRow> <textview android:gravity= "right" android:textstyle= "bold" and roid:padding= "3dip" android:text= "User name:"/> <edittext android:id= "@+id/username "Android:padding=" 3dip "android:scrollhorizontally=" true "/> </TableRow> < tablerow> <textview android:gravity= "right" android:textstyle= "bold" Android            :p adding= "3dip" android:text= "User password:"/> <edittext android:id= "@+id/password" android:padding= "3dip" android:password= "true"/> </TableRow> <tablerow Andro Id:gravity= "Right" > &Lt Button android:id= "@+id/cancel" android:text= "Cancel"/> <button Android : id= "@+id/login" android:text= "Login"/> </TableRow></TableLayout>

Java source code file: Mainactivity.java
Package Com.rainsong.edittextdemo;import Android.app.activity;import Android.os.bundle;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{Button btn_login;    Onclicklistener Listener_login; /** called when the activity is first created.        */@Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);                Setcontentview (R.layout.main); Listener_login = new Onclicklistener () {public void OnClick (View v) {EditText username = (Edit                Text) Findviewbyid (r.id.username);                EditText password = (EditText) Findviewbyid (R.id.password); Toast.maketext (mainactivity.this, "User name:" + username.gettext () + ", User password:" + password.gettext (), Toast.            Length_short). Show ();                }        }; Btn_login =(Button) Findviewbyid (R.id.login);    Btn_login.setonclicklistener (Listener_login); }}

API Knowledge Points
Android.widget.EditText
public class
EditText
Extends TextView

Known Direct subclasses
Autocompletetextview, Extractedittext, Searchedittext

Known Indirect subclasses
Multiautocompletetextview

Class Overview
EditText is a thin veneer over TextView, configures itself to be editable.

Public constructors
EditText (Context context)
EditText (context context, AttributeSet attrs)
EditText (context context, AttributeSet attrs, int defstyleattr)
EditText (context context, AttributeSet attrs, int defstyleattr, int defstyleres)

Editable GetText ()
Return the text the TextView is displaying.


Android Common UI Components-EditText

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.