Try this method to hide keyboard when you need
 public void hideTypingKeyboard() {
        try {
            if(getCurrentFocus() != null) {
                   InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
                   imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
 }
EDIT:
 public static void hideEditTextKeyboard(InputMethodManager imm, EditText edittext) {
        if (edittext != null) {
            InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);
        }
    }
I hope it helps!