title: How to hide the soft keyboard inside a fragment?
body: <p>I have a <code>FragmentActivity</code> using a <code>ViewPager</code> to serve several fragments. Each is a <code>ListFragment</code> with the following layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
      &lt;LinearLayout
          android:orientation="vertical"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:padding="8dp"&gt;
          &lt;ListView android:id="@id/android:list"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent" /&gt;
  
          &lt;EditText android:id="@+id/entertext"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>When starting the activity, the soft keyboard shows. To remedy this, I did the following inside the fragment:</p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      //Save the container view so we can access the window token
      viewContainer = container;
      //get the input method manager service
      imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
      . . .
  }
  
  @Override
  public void onStart() {
      super.onStart();
  
      //Hide the soft keyboard
      imm.hideSoftInputFromWindow(viewContainer.getWindowToken(), 0);
  }
  </code></pre>
  
  <p>I save the incoming <code>ViewGroup container</code> parameter from <code>onCreateView</code> as a way to access the window token for the main activity. This runs without error, but the keyboard doesn't get hidden from the call to <code>hideSoftInputFromWindow</code> in <code>onStart</code>.</p>
  
  <p>Originally, I tried using the inflated layout instead of <code>container</code>, i.e:</p>
  
  <pre><code>imm.hideSoftInputFromWindow(myInflatedLayout.getWindowToken(), 0);
  </code></pre>
  
  <p>but this threw a <code>NullPointerException</code>, presumably because the fragment itself isn't an activity and doesn't have a unique window token?</p>
  
  <p>Is there a way to hide the soft keyboard from within a fragment, or should I create a method in the <code>FragmentActivity</code> and call it from within the fragment?</p>