title: Android: how to close explicitly displayed soft keyboard?
body: <p>I am showing a dialog for textinput and would like to automatically display the soft keyboard if no hard keyboard is open.  In order to get it to display on my Samsung Galaxy Tab, I had to use the SHOW_FORCED flag, the SHOW_IMPLICIT flag did not work.  Also, on dialog dismissal I would like to close the keyboard if I forced its display.  However, the code I'm using below does not close the keyboard on my Galaxy Tab; I assume it is because I used the Explicit flag to show.</p>
  
  <pre><code>    /* from the dialog constructor*/
  
      InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.restartInput(mEditText);
  
      //only display if there is no hard keyboard out 
      Configuration config = getResources().getConfiguration();
      if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES)
      {
        mForcedKeyboardDisplay = true;
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
      }
  
  
      /* from the onDismiss() method*/
  
      //if we previously forced keyboard display, force it to close
      if (mForcedKeyboardDisplay)
      {
         InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
         imm.restartInput(mEditText);
  
         imm.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
         //this doesn't work either 
         //imm.hideSoftInputFromWindow(mEditText.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
         //nor does this
         //imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
      }
  </code></pre>