Android UI控件详解-EditText(编辑框)
作者:互联网
package com.bdqn.edittext;
import android.os.Bundle;
import android.app.Activity;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.EditText;
import android.widget.TextView;
/**
*
* @author TXF
*
*/
public class MainActivity extends Activity {
private EditText met;
private TextView mtv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// 通过findViewById找到TextView和EditTextview对象
setContentView(R.layout.activity_main);
met = (EditText) findViewById(R.id.et);
mtv = (TextView) findViewById(R.id.tv);
// 设置软件盘点击监听器
met.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View arg0, int arg1, KeyEvent arg2) {
mtv.setText(met.getText().toString());
// 这里注意下,如果返回值为false则结果正常,
// 如果返回值为true,则结果为键盘事件无法监听,按任何键都无响应,除了Home键。
ret
标签:控件,findViewById,EditText,met,UI,import,android,TextView 来源: https://blog.csdn.net/weixin_38107457/article/details/120237706