I have a dialog box open in my android app, and I have a button when clicked will dismiss the dialog box. The problem is there is also a textedit field, and if its focused and the keyboard is showing, then when I click the cancel button, then dialog goes away, but the keyboard is still showing.
I want to also dismiss the keyboard.
I was searching around, and for threads like this Hide soft keyboard after dialog dismiss
But none of the solutions worked for me. By the way the edittext is a number input type, if that makes a difference somehow.
Does anyone know how to fix this?
Thanks
public void HandleTeamManagement() { final Dialog teamDialog = new Dialog(this); teamDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); teamDialog.setContentView(R.layout.dialog_team_management); final EditText mergeNum = (EditText) teamDialog.findViewById(R.id.group); InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(mergeNum.getWindowToken(), 0); // Setting Negative "NO" Button Button cancelButton = (Button) teamDialog.findViewById(R.id.cancel); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { teamDialog.dismiss(); } }); // Showing Alert Dialog teamDialog.show(); }
InputMethodManager imm = (InputMethodManager)getSystemService( Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);?