I am customizing DatePickerDialog to add some of my functionality for native DatePicker. that is working as expected. But day, month and year fields of DatepickerDialog are editable by default. so when i focus those editable input fields soft keyboard will be open by default and used will be able to edit the date/month/year and when user edit the day/month/year ans press set/cancel edited date DatePickerDialog is getting closed and functionality is working properly. Here my issue is when user edit the day/month/year ans press set/cancel edited date DatePickerDialog is getting closed and softkeyboard is still opened. its not getting closed as soon as DatePickerDialog is dismissed. so for that i tried to hide the softkeyboard with the following code.
private DialogInterface.OnDismissListener myOnDismissListener = new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
InputMethodManager imm = (InputMethodManager) ((Activity) ctContext)
.getSystemService(Activity.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
}
};
But this is not working. So I tried to toggle the softkeyboard with the following code.
private DialogInterface.OnDismissListener myOnDismissListener = new DialogInterface.OnDismissListener() {
public void onDismiss(DialogInterface dialog) {
InputMethodManager imm = (InputMethodManager) ((Activity) ctContext)
.getSystemService(Activity.INPUT_METHOD_SERVICE);
if(imm.isActive())
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}
};
But here imm.isActive() is always returning false. if i remove that if(imm.isActive()) condition its working when softkeyboard is open. but when softkeyboard is not opened and used just opened DatePickerDialog and set or cancel the date by changing with arrows softkeyboard is getting opened on dismiss of DatePickerDialog. So i need to get that imm.isActive() value properly. but its always returning false.
So some one please help me to get the proper way to decide whether softkeyboard is opened or not.