androd开发中EditText的setOnKeyListener事件

package irdc.practice1;

import irdc.practice1.R;

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 practice1 extends Activity

{

/*声明 TextView、EditText对象*/

private TextView mTextView01;

<span style="color:#ff0000">private EditText mEditText01; </span>


/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);


/*取得TextView、EditText*/

mTextView01 = (TextView)findViewById(R.id.myTextView);

<span style="color:#ff0000">mEditText01 = (EditText)findViewById(R.id.myEditText);</span>


/*设置EditText用OnKeyListener事件来启动*/

<span style="color:#ff0000">mEditText01.setOnKeyListener(new EditText.OnKeyListener()

{

@Override

public boolean onKey(View arg0, int arg1, KeyEvent arg2)

{

// TODO Auto-generated method stub

/*设置TextView显示EditText所输入的内容*/

mTextView01.setText(mEditText01.getText());

return false;

}

}




你可能感兴趣的:(事件,EditText,androd)