title: Close keyboard on click outside of EditText in fragment
body: <p>I have a fragment containing an EditText for search input and a ListView. I've got the search part working, but now I want to close the keyboard when the user clicks the on the screen outside of the EditText. I'd also like to consume the click event (because it is a ListView, if I don't consume the click event the user may accidentally click on a ListView item they didn't want to open)</p>
  
  <p>I know how to do this in an activity, but it seems to be different for fragments.</p>
  
  <p>What I've tried so far:</p>
  
  <ul>
  <li><p>Implement <code>View.OnClickListener</code> in the fragment and implement onClick as such:</p>
  
  <pre><code>@Override
  public void onClick(View v) {
      System.out.println("onClick true");
      if (!(v instanceof EditText)) {
          InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.
                  INPUT_METHOD_SERVICE);
          if (getActivity().getCurrentFocus() != null) {
              imm.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 0);
          }
      }
  }
  </code></pre></li>
  </ul>
  
  <p>This never seemed to post "onClick true" when I clicked.</p>
  
  <ul>
  <li><p>Override onTouchEvent in the fragment's activity and implement onTouchEvent as such:</p>
  
  <pre><code>@Override
  public boolean onTouchEvent(final MotionEvent event) {
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.
              INPUT_METHOD_SERVICE);
      if (getCurrentFocus() != null) {
          imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
      }
      return true;
  }
  </code></pre></li>
  </ul>
  
  <p>Any help would be greatly appreciated. Thanks in advance.</p>