EditText Control for android

Source: Internet
Author: User

[Java]
<Span style = "font-size: 18px;">
</Span>
[Java] view plaincopyprint?
<Span style = "font-size: 18px;"> 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 );
// Set the prompt content when edittext is empty
EditText1.setHint ("Enter aaaaa content ");

// <Span style = "color: # ff0000;"> set edittext event listening .... <Span style = "font-family: Arial; line-height: 26px; text-align: left;"> the only key in the main program 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. </Span>
// New EditText. OnKeyListener () is the same as new OnKeyListener ().
EditText1.setOnKeyListener (new EditText. OnKeyListener (){
Public boolean onKey (View arg0, int arg1, KeyEvent arg2)
{
TextView1.setText ("the text box content is" + EditText1.getText (). toString ());
Return false;
}
});
}
} </Span>

Note the following in main. xml:
Android: layout_x and android: layout_y are only valid in absolute layout...
[Html]
<Span style = "font-size: 18px;"> <? 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"
<Span style = "color: # ff0000;"> android: layout_x = "29px"
Android: layout_y = "30px" </span>
/>
 
<TextView
Android: id = "@ + id/myTextView"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: text = "@ string/mytext"/>
 
</LinearLayout> </span>

Author: Bill_Ming

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.