I am working on a messaging app in which I have an EditText for the user to type his message. I have provided a 'Send' button in keyboard with setImeOptions()
method. However, whenever the user hits the 'Send' Button, the EditText loses focus. (I am doubtful about the word 'focus', but what I mean is the keyboard disappears..)
I find it a bit inconvenient as the user has to click on EditText again to get the keyboard after each send. I have tried editText1.requestFocus()
in the code as follows :
editText1.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "send" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
// Perform action on key press
adapter.add(new OneComment(false, editText1.getText().toString()));
editText1.setText("");
editText1.requestFocus();
return true;
}
return false;
}
});
But this doesn't work...please suggest a workaround..thanks :)