title: How to avoid dispatchTouchEvent being called when click button
body: <p>In my Activity, I have an <code>EditText</code> and a <code>Button</code>.  I overrided the <code>dispatchTouchEvent</code> to hide the soft keyboard when click the other area of the screen than the <code>EditText</code>.</p>
  
  <pre><code>@Override
  public boolean dispatchTouchEvent(MotionEvent event) {
      View view = getCurrentFocus();
      boolean ret = super.dispatchTouchEvent(event);
  
      if (view instanceof EditText) {
          View w = getCurrentFocus();
          int scrcoords[] = new int[2];
          w.getLocationOnScreen(scrcoords);
          float x = event.getRawX() + w.getLeft() - scrcoords[0];
          float y = event.getRawY() + w.getTop() - scrcoords[1];
  
          if (event.getAction() == MotionEvent.ACTION_UP
                  &amp;&amp; (x &lt; w.getLeft() || x &gt;= w.getRight() || y &lt; w.getTop() || y &gt; w
                          .getBottom())) {
              InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
              imm.hideSoftInputFromWindow(getWindow().getCurrentFocus()
                      .getWindowToken(), 0);
          }
      }
      return ret;
  }
  </code></pre>
  
  <p>The issue is, every time I click the <code>Button</code>, the <code>dispatchTouchEvent</code> will be called, so the soft keyboard will disappear, which is not what I want.  I don't want to hide the keyboard when I click the <code>Button</code>.  What I'm thinking is that is it possible to avoid calling the <code>dispatchTouchEvent</code> when I click the <code>Button</code>?  </p>
  
  <p>Any feedback will be highly appreciated.</p>