I am using a FrameLayout to show an EditText and a ListView (with checkboxes) alternately. When showing an EditText, I would like the soft keyboard to be shown. And when showing the ListView, I would like the soft keyboard to be hidden. Now usually a focus is needed in order to hide the soft keyboard. When my ListView gets shown, then getCurrentFocus() returns null. Is there a way to hide the soft keyboard, without having a focus?
I am showing the soft keyboard like that:
public static void requestFocusAndMoveCursorToTheEndAndShowKeyboard(final EditText editTextParam, final Activity activityParam) {
    if (editTextParam == null) {
        return;
    }
    if (editTextParam.requestFocus()) {
        editTextParam.setSelection(editTextParam.getText().length()); // move Cursor to the end of the EditText
        InputMethodManager imm = (InputMethodManager) activityParam.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
    }
}
And I am trying to hide the soft keyboard like that:
public static void hideSoftInputKeyboardFromWindow(Activity activityParam) {
    if (activityParam == null) {
        return;
    }
    View view = activityParam.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputMethodManager = (InputMethodManager) activityParam.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputMethodManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
 
     
     
     
     
     
     
    