[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