Reputation: 3971
I have a chat feature in my application. everything is working fine. The problem i am facing is that i have an edittext and a button for sending the text. Now when i press the send button the keyboard comes down which i don't want. Because it is very annoying for the user to open the keyboard after sending every message. Does anyone have any solution for this. it is a very silly issue but it is quite important for me. and is there any change in xml or manifest which we can make which will help solve this problem
Upvotes: 3
Views: 116
Reputation: 510
if you return true
from your onEditorAction
method, action is not going to be handled again. In this case you can return true
to not hide keyboard when action is EditorInfo.IME_ACTION_DONE
.
Hope it will help !
Upvotes: 0
Reputation: 1368
According to this answer.
EditText txtEdit = (EditText) findViewById(R.id.txtEdit);
txtEdit.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// your additional processing...
return true;
} else {
return false;
}
}
});
Let me know if it solves your problem.
Upvotes: 0
Reputation: 1770
Try the below code:
@Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// User has pressed Back key. So hide the keyboard
InputMethodManager mgr = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(this.getWindowToken(), 0);
// TODO: Hide your view as you do it in your activity
} else if (keyCode == KeyEvent.KEYCODE_MENU) {
// Eat the event
return true;
}
return false;
}
Upvotes: 1
Reputation: 2223
I was faced with the same thing in one of my project's. Try doing this to show keyboard
private void showKeyboard(){
InputMethodManager imgr = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imgr.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
yourEditText.requestFocus();
}
This makes the keyboard go down only when back is pressed.
Upvotes: 0