<Linearlayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
androidrientation="vertical" >
<editText
android:id="@+id/input"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<textView
android:id="@+id/output"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
主Activity程序:
package nbe.sense7.vinci.edittext;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class EditTextDemoActivity extends Activity {
private EditText editText;
private TextView textView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText)findViewById(R.id.input);
textView = (TextView)findViewById(R.id.output);
//设置EditText按键输入时的事件
editText.setOnKeyListener(new EditText.OnKeyListener(){
@Override
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
// TODO Auto-generated method stub
textView.setText(editText.getText());
return false;
}
});
}
}