Reputation: 4816
OK, so I have an activity that expects from 2 to 6 numeric inputs. When the user has finished, a button is pressed to initiate processing and then intermediate results are displayed. The problem is that I can't get the keyboard to disappear and it covers up the Scrollable area where the results are to appear.
I am using confirmButton.setOnClickListener(new View.OnClickListener() { public void onClick(View view) {
//hide keyboard :
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
// do stuff
}
});
but this doesn't hide the keyboard. I have to use the confirm button - since some of the inputs are optional. So I can't rely on a focus change listener or similar. Is being inside the view of the button affecting my ability to hide the keyboard in the parent window?
Or is something else more sinister going on?
I can click the back button and keyboard leaves, or I can click "NEXT" through all the expected inputs and then click the keyboard's "OK" but that forces the user to do unnatural things.
Any ideas?
Upvotes: 0
Views: 1141
Reputation: 1730
To hide the softkeyboard, you must use the InputMethodManager. Here is an example:
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(editConfirmPass.getWindowToken(), 0);
Upvotes: 4