Edittext Control for Android

Source: Internet
Author: User
 
Package ZM. DMY; import android. app. activity; import android. OS. bundle; import android. view. keyevent; import android. view. view; import android. view. view. onkeylistener; import android. widget. edittext; import android. widget. textview; public class editview1activity extends activity {/** called when the activity is first created. */private textview textview1; private edittext edittext1; @ override public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); textview1 = (textview) findviewbyid (R. id. mytextview); edittext1 = (edittext) findviewbyid (R. id. myedittext); // sets the prompt content edittext1.sethint when edittext is empty ("Enter AAAAA content ");//Set edittext event listening ....MasterProgramThe only key is to use edittext. onkeylistener is used to intercept the keyboard input events of edittext. You only need to override the onkey () method. In the onkey () method, set edittext. the text obtained by gettext () is displayed in textview. // New edittext. onkeylistener () and new onkeylistener () are the same as edittext1.setonkeylistener (New edittext. onkeylistener () {public Boolean onkey (view arg0, int arg1, keyevent arg2) {textview1.settext ("the content of the text box is" + edittext1.gettext (). tostring (); Return false ;}});}}


Note the following in Main. xml:

Android: layout_x and Android: layout_y are only valid in absolute layout...

<? XML version = "1.0" encoding = "UTF-8"?> <Linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: Orientation = "vertical"> <edittext Android: id = "@ + ID/myedittext" Android: layout_width = "fill_parent" Android: layout_height = "wrap_content" Android: textsize = "15sp"Android: layout_x = "29px" Android: layout_y = "30px"/> <Textview Android: Id = "@ + ID/mytextview" Android: layout_width = "fill_parent" Android: layout_height = "fill_parent" Android: TEXT = "@ string/mytext"/> </linearlayout>

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.