title: Implementing onKeyPreIme(int keyCode, KeyEvent event) in Fragment
body: <p>I cannot figure how to implement <code>onKeyPreIme(int keyCode, KeyEvent event)</code> in a <code>Fragment</code>. </p>
  
  <pre><code>@Override
  public boolean onKeyPreIme(int keyCode, KeyEvent event) {
      if (keyCode == KeyEvent.KEYCODE_BACK &amp;&amp; 
          event.getAction() == KeyEvent.ACTION_UP) {
              // do your stuff
              return false;
      }
      return super.dispatchKeyEvent(event);
  }
  </code></pre>
  
  <p>I tried a lot but nothing works. Also, I could not find anything on Google or Stack Overflow. I would like to perform an action when the back key is pressed and the softkeyboard is up. Setting an <code>onKeyListener</code> on my <code>EditText</code>s did not work, since <code>KeyEvent.KEYCODE_BACK</code> is not called when the soft keyboard is up. I appreciate any help and source code.</p>