I have extended AlertDialog with my class that displays my XML layout. I don't use AlertDialog's standard buttons, I have my own OK and Cancel buttons. Listener for them calls dismiss()
. The problem is if I was editing EditText's contents and then pressed OK (it's an Android 3.1 tablet, keyboard doesn't prevent me from interacting with the dialog), the dialog will hide but keyboard won't, it'll stay in background. What could be the reason and how to fix it?
Here's a constructor of my dialog, to give the idea:
public NetworkCameraParametersDialog(Context context ) {
super(context);
View content = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.dialog, null);
setView(content);
Button btnOk = (Button) content.findViewById(R.id.btn_Ok);
btnOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Some work
dismiss();
}
});
Button btnClose = (Button) content.findViewById(R.id.btn_Close);
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
You can force soft keyboard to hide:
try {
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), 0);
} catch (Exception e) {}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With