title: "Press and hold" button on Android needs to change states (custom XML selector) using onTouchListener
body: <p>I've got a button graphic which needs to have "press and hold" functionality, so instead of using onClickListener, I'm using onTouchListener so that the app can react to</p>
  
  <pre><code> MotionEvent.ACTION_DOWN,
  </code></pre>
  
  <p>and</p>
  
  <pre><code> MotionEvent.ACTION_UP
  </code></pre>
  
  <p>Depending on how quickly those two events are triggered, I can run a "pressAndHoldHandler" in the time between the two.</p>
  
  <p>Anyway, long story short: I have numerous "basic" buttons in the same app that don't require the press and hold functionality, so they are using the onClickListener.</p>
  
  <p>Every single one of these buttons have been customized graphically with their own XML selector file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;selector
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
      &lt;item
          android:state_enabled="false"
          android:drawable="@drawable/btn_chicken_off" /&gt;
  
      &lt;item
          android:state_enabled="true"
          android:state_pressed="true"
          android:drawable="@drawable/btn_chicken_s3" /&gt;
  
      &lt;item
          android:state_enabled="true"
          android:state_focused="true"
          android:drawable="@drawable/btn_chicken_s2" /&gt;
  
      &lt;item
          android:state_enabled="true"
          android:drawable="@drawable/btn_chicken_off" /&gt;
  
  &lt;/selector&gt;
  </code></pre>
  
  <p>So, the problem here is: The above selector doesn't get accessed with the onTouchListener. Only the onClickListener will pull in the state changes with the onClick() section of its own method, so these "press and hold" buttons never change state. Pretty terrible feedback for the user.</p>
  
  <p>I'm currently forcing the above inside the switch case of ACTION_DOWN and ACTION_UP by doing the following:</p>
  
  <pre><code>if (action == MotionEvent.ACTION_DOWN) {
      btn_chicken.setBackgroundResource(R.drawable.btn_chicken_s3);
  }
  else
      if (action == MotionEvent.ACTION_UP) {
          btn_chicken.setBackgroundResource(R.drawable.btn_chicken_off);
      }
  </code></pre>
  
  <p>But it seems like a hack, and it's missing the "focused but not pressed" stage.</p>
  
  <p>Anybody tripped across this before?</p>