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
Asked
Active
Viewed 105 times
3
-
i dont know how but the issue got solved, there was a progressdialog which was shown when the button was pressed. i just commented the line and all the progressview from the class then the issue was solved. weird but true – Parth Anjaria Feb 23 '16 at 12:13
4 Answers
1
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;
}

Pradeep Gupta
- 1,770
- 1
- 9
- 23
0
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.

Shashank Udupa
- 2,173
- 1
- 19
- 26
0
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.
-
I meant your code, not mine. I want to see your `Activity`. So I can better understand your situation. – Emzor Feb 23 '16 at 14:40
0
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 !

Rahul
- 510
- 3
- 8
-
it is not working. the code below i tried. but the keyboard still minimizes – Parth Anjaria Feb 23 '16 at 10:51
-
-
yes i added it in the xml and i added the code as shown below by @Emzor – Parth Anjaria Feb 23 '16 at 11:31
-
Please upload your XML + Activity code and give links for accessing them, after that I can help you with this. Because this solution should work. Please upload and let me know. – Rahul Feb 23 '16 at 11:38