我希望我的测试数据在 Enter 按键后转到另一个窗口,就像点击发送按钮一样。
我正在使用此代码:
text1 = ((TextView) findViewById(R.id.textMsg));
text1.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event){
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
Toast.makeText(IMSendData.this, text1.getText(), Toast.LENGTH_SHORT).show();
return true;
}
return false;
}
});
按 Enter 键后,使用此代码,进入发送按钮,然后按第二个 Enter 键,按下测试数据进入窗口。
我只想按 Enter 按钮一次,然后文本转到窗口。
答案 0 :(得分:0)
you go through this..
sendData = (EditText) findViewById(R.id.message);
sendData.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode ==
KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
adapter.add(new OneComment(false,
sendData.getText().toString()));
sendData.setText("");
return true;
}
return false;
}
});