I want my test data goes to another window after Enter key press, like a click on the send button.
I’m using this code:
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;
}
});
Using this code after I press the Enter key, its goes on send button, and after second Enter key press the test data goes to the window.
I want to press Enter button only once and then the text go to the window.
1 Answer