title: DialogFragment with edittext doesn't lose keyboard after dismissed
body: <p>I have a custom DialogFragment with a single EditText and no buttons. After the text is entered into the edittext and I press "done", the keyboard stays visible upon returning to the host activity, even though the dialog is dismissed. It changes to a numerical keyboard, because the field in the host activity it focuses on is a numerical entry only <code>edittext</code> - but it may also focus on an edittext field I with normal text entry (and thus remain a normal keyboard) depending on where I left the cursor after I start the dialog fragment.</p>
  
  <p>I have tried everything I could find (have googled and stackoverflowed a lot).</p>
  
  <p>I based the dialogfragment on <a href="http://android-developers.blogspot.co.uk/2012/05/using-dialogfragments.html" rel="nofollow noreferrer">this</a> code - it is very similar. </p>
  
  <p>The problem is very similar to <a href="https://stackoverflow.com/questions/12997273/alertdialog-with-edittext-open-soft-keyboard-automatically-with-focus-on-editte">this</a>, and I think the causes may be similar, but I have no buttons in my DialogFragment so I can't follow that solution though I don't think it matters I can follow it closely enough.</p>
  
  <p>I have tried using <code>inputmethodmanager</code> as suggested there and <a href="https://stackoverflow.com/questions/12997273/alertdialog-with-edittext-open-soft-keyboard-automatically-with-focus-on-editte">here</a> to dismiss the keyboard, within the interface method (implemented in the host activity), and <code>onCreateView</code>, <code>onEditorAction</code> and <code>onDismiss</code> within the DialogFragment class. Also tried <code>getDialog().getWindow().setSoftInputMode(LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);</code> (also using <code>SOFT_INPUT_STATE_HIDDEN</code>) in the DialogFragment class methods. Did try <code>mEditText.clearFocus();</code> too in all the DF class methods to no avail.</p>
  
  <p>Can anyone help at all? Is it to do with <a href="http://android-developers.blogspot.co.uk/2012/05/using-dialogfragments.html" rel="nofollow noreferrer">David Chandler's code</a> I based mine on, or something I'm doing wrong specifically. All help most appreciated.</p>
  
  <p>I include my DF class below in case anyone wants to look. </p>
  
  <pre><code>public class SetText extends DialogFragment {
  
  
  public interface SetTextBoxDialogListener{
      void onFinishEnteringName(String name);
  }
  
  
  private EditText mEditText;
  
  //Empty constructor req'd for dialogfragment.
  public SetText(){
  
  }
  
  
  //Build view
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle saveInstanceState) {
      View view = inflater.inflate(R.layout.activity_set_the_text, container);
      mEditText =  (EditText) view.findViewById(R.id.nameText);
      getDialog().setTitle("Enter Name");
  
  
      //removing these 2 lines of code has no effect
      mEditText.requestFocus();
      getDialog().getWindow().setSoftInputMode(LayoutParams.VISIBLE);
  
  
      mEditText.setOnEditorActionListener(new OnEditorActionListener() {
          public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (EditorInfo.IME_ACTION_DONE==actionId){
                  //return text to activity
                  SetEnterNameDialogListener activity = (SetEnterNameDialogListener) getActivity();
                  activity.onFinishEnteringName(mEditText.getText().toString());
  
  
                  dismiss();
                  return true;
              }
              //code for 2 lines below had now effect, even placed above dismiss
              InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
  
          return false;
      }
  });
  
  return view;
  }
  }
  </code></pre>