main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/myEditText"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/myTextView"/>
</LinearLayout>
MainActivity.java
package zyf.EX_Ctrl_1;
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 MainActivity extends Activity {
private TextView mTextView01;
private EditText mEditText01;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
/* 取得TextView、EditText */
mTextView01 = (TextView) findViewById(R.id.myTextView);
mEditText01 = (EditText) findViewById(R.id.myEditText);
/* 设置EditText 用OnKeyListener 事件来启动*/
mEditText01.setOnKeyListener(new EditText.OnKeyListener(){
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
mTextView01.setText(mEditText01.getText().toString());
return false;
}
});
}
}
运行结果: