0

I'm in a situation in which I have an editText. When I press add in the edit text i'm adding a member in a list. When is added (or not) I'm opening a custom Dialog.

In my activity i have this code when clicking on add button in the edit text:

  customDialogTeamMember = new CustomDialogTeamMember(............);
  customDialogTeamMember.makeDialog();
  editText.getText().clear();
  editText.clearFocus();
  hideSoftKeyboard();

My hideSoftKeyboard() is defined like:

public void hideSoftKeyboard() {
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
}

This method works in other sections of the app. But here is not working!

The custom dialog opens. When i close it the keyboard keeps on the screen. What could be the problem?!

denno
  • 119
  • 1
  • 4
  • 15

5 Answers5

6

To show and hide Keyboard

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
//Hide:
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
//Show
imm.toggleSoftInput(InputMethodManager.SHOW_IMPLICIT, 0);




private void hideKeyboard() {   
    // Check if no view has focus:
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

private void showKeyboard() {   
    // Check if no view has focus:
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }
}
pradeep
  • 307
  • 1
  • 8
1
// minimize keyboard
    try {
        InputMethodManager imm = (InputMethodManager)activity.getSystemService(INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(dialog.getCurrentFocus().getWindowToken(), 0);
    } catch (Exception e) {}
Samad
  • 1,538
  • 2
  • 17
  • 30
0

i used this on my Case.

// for hide keyboard
    public static void hideKeyboard(Activity activity) {
        InputMethodManager iim = (InputMethodManager)
                activity.getSystemService(Context.INPUT_METHOD_SERVICE);

        if (activity.getCurrentFocus() != null)
            iim.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);
    }

call this method as your requirements.and let me know..Hope this will helps.

Sagar Aghara
  • 600
  • 7
  • 19
0
// Check if no view has focus:
View view = this.getCurrentFocus();
if (view != null) {  
     InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
     imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

Check this out

Mayur Kharche
  • 697
  • 1
  • 8
  • 27
0

To hide and show the soft keyboard,use the following method

private void hideKeyboard() {   
    // Check if no view has focus:
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}

private void showKeyboard() {   
    // Check if no view has focus:
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
    }
}
Sathish Kumar VG
  • 1,936
  • 1
  • 9
  • 19