title: How to implement onBackPressed for Android Fragment?
body: <p>I want to implement custom onBackPressed methods for all my fragments which are included in my Main activity. But I am not getting a hook when my device back is pressed. I tried to implement few stuffs available in SOF, but none of them work properly.
  Please Help!</p>
  
  <p>I tried this in onCreateView:</p>
  
  <pre><code>rootView.setFocusableInTouchMode(true);
  rootView.requestFocus();
  rootView.setOnKeyListener( new OnKeyListener()
  {
  @Override
  public boolean onKey( View v, int keyCode, KeyEvent event )
  {
      if( keyCode == KeyEvent.KEYCODE_BACK)
      {
          return true;
      }
      return false;
  }
  } );
  </code></pre>