title: The keyboard is not opening / closing when I want it to
body: <p>I have 2 tabs. </p>
  
  <p>When 1 is opened, I want to show the keyboard.
  When the other is opened, I want to make sure the keyboard is closed.</p>
  
  <p>Here is my code for the fragment of the tab I want to show the keyboard (when this is opened, it auto-focuses an EditText the user will use to perform a search:</p>
  
  <pre><code>public class AddFoodSearchFragment extends Fragment {       
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          View V = inflater.inflate(R.layout.fragment_add_food_search, container, false);
  
          getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
  
          return V;
      }    
  }
  </code></pre>
  
  <p>And the fragment to close it:</p>
  
  <pre><code>public class AddFoodFormFragment extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          View V = inflater.inflate(R.layout.fragment_add_food_form, container, false);
  
          getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
  
          return V;
      }
  }
  </code></pre>
  
  <p>Why is it not responding the way I want it to? I don't understand what is so difficult about this.</p>
  
  <p>EDIT</p>
  
  <p>I could just as well do this via adding onPause() to my 1 fragment, but its still not working:</p>
  
  <pre><code>public class AddFoodSearchFragment extends Fragment {       
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          View V = inflater.inflate(R.layout.fragment_add_food_search, container, false);
          getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
          return V;
      }
  
      @Override
      public void onPause() {
          super.onPause();
          getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
      }
  }
  </code></pre>