我在将文本从EditText
转移到TextView
时遇到问题(我还测试过将其转移到EditText
并将属性设置为false)并且它可以正常工作在模拟器上确定,但是当我在真实设备上测试它时,它总是在尝试设置文本时崩溃。
我还测试过只发送一个文本(见注释行),结果相同
EditText editText = (EditText) findViewById(R.id.Texte);
editText.setOnEditorActionListener(new OnEditorActionListener()
{
@Override
public boolean onEditorAction(TextView arg0, int arg1, KeyEvent arg2)
{
int A;
boolean handled = false;
if (arg2.getKeyCode() == KeyEvent.KEYCODE_ENTER)
{
TextView Etiqueta = (TextView)findViewById(R.id.textView1);
Etiqueta.setText(arg0.getText().toString());
//Etiqueta.setText("40");
handled = true;
}
return handled;
}
});
答案 0 :(得分:0)
我找到了使用onKeyListener的另一种方法,它没有给出错误
@Override
public boolean onKey(View view, int keyCode, KeyEvent event)
{
TextView Etiqueta = (TextView)findViewById(R.id.textView1);
TextView Etiqueta2 = (TextView)findViewById(R.id.textView2);
EditText myEditText = (EditText) view;
if ( event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
{
if (!event.isShiftPressed())
{
//Log.v("AndroidEnterKeyActivity","Enter Key Pressed!");
switch (view.getId())
{
case R.id.Texte:
Etiqueta.setText(myEditText.getText());
break;
case R.id.Texte2:
Etiqueta2.setText(myEditText.getText());
break;
}
return true;
}
}
return false;
}