main.xml代码如下:
<?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" >
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/edit"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
.java代码如下:
package org.lxh.demo;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Hello extends Activity {
private TextView txt=null;
private EditText edit=null;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); // 生命周期方法
super.setContentView(R.layout.main); // 设置要使用的布局管理器
this.edit=(EditText)super.findViewById(R.id.edit);
this.txt=(TextView)super.findViewById(R.id.text);
this.edit.setOnKeyListener(new OnKeyListenerImpl());
}
private class OnKeyListenerImpl implements OnKeyListener{
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
String str=Hello.this.edit.getText().toString();
Hello.this.txt.setText(str);
return false;
}