title: Why doesn't the pressed state of a ColorStateList work with a ListView item?
body: <p>I am trying to set up a <code>ListView</code> with items that have varying background colors, so my adapter's <code>getView()</code> method calls <code>setBackgroundResource()</code> with an appropriate drawable resource for the desired background color.</p>
  
  <p>If I use a <code>ColorDrawable</code> that references a <code>ColorStateList</code> as its color, the color for the pressed state from the <code>ColorStateList</code> is not drawn when I tap on the item.</p>
  
  <p>If I use a <code>StateListDrawable</code> that references a <code>ColorDrawable</code> for the pressed state and a different <code>ColorDrawable</code> for the unpressed state, I get the desired highlighting effect when I tap on the item.</p>
  
  <p>I've set up a simple project to demonstrate this. Here is the <code>getView()</code> method from the <code>ListAdapter</code>:</p>
  
  <pre><code>@Override
  public View getView(int position, View convertView, ViewGroup parent) {
      View retval = getLayoutInflater().inflate(android.R.layout.simple_list_item_1, parent, false);
      TextView textView = (TextView)retval.findViewById(android.R.id.text1);
      textView.setText("" + position);
  
      switch ( position ) {
          case 0:
              retval.setBackgroundResource(R.drawable.list_background_item_0);
              break;
  
          case 1:
              retval.setBackgroundResource(R.drawable.list_background_item_1);
              break;
      }
  
      return retval;
  }
  </code></pre>
  
  <p>res/drawable/list_background_item_0.xml:</p>
  
  <pre><code>&lt;color xmlns:android="http://schemas.android.com/apk/res/android"
      android:color="@color/list_background_item_0" /&gt;
  </code></pre>
  
  <p>res/color/list_background_item_0.xml:</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:state_pressed="true" android:color="@color/list_background_item_0_pressed"/&gt;
      &lt;item android:color="@color/list_background_item_0_default"/&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>res/drawable/list_background_item_1.xml:</p>
  
  <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item android:state_pressed="true" android:drawable="@drawable/list_background_item_1_pressed" /&gt;
      &lt;item android:drawable="@drawable/list_background_item_1_default" /&gt;
  &lt;/selector&gt;
  </code></pre>
  
  <p>res/drawable/list_background_item_1_default.xml:</p>
  
  <pre><code>&lt;color xmlns:android="http://schemas.android.com/apk/res/android" 
      android:color="@color/list_background_item_1_default" /&gt;
  </code></pre>
  
  <p>res/drawable/list_background_item_1_pressed.xml:</p>
  
  <pre><code>&lt;color xmlns:android="http://schemas.android.com/apk/res/android" 
      android:color="@color/list_background_item_1_pressed" /&gt;
  </code></pre>
  
  <p>res/values/colors.xml:</p>
  
  <pre><code>&lt;resources&gt;
      &lt;color name="list_background_item_0_default"&gt;#FFCCCC&lt;/color&gt;
      &lt;color name="list_background_item_0_pressed"&gt;#996666&lt;/color&gt;
      &lt;color name="list_background_item_1_default"&gt;#CCFFCC&lt;/color&gt;
      &lt;color name="list_background_item_1_pressed"&gt;#669966&lt;/color&gt;
  &lt;/resources&gt;
  </code></pre>
  
  <p>List item 0 is configured with a <code>ColorDrawable</code> that references a <code>ColorStateList</code> and does not display a highlight when pressed. List item 1 is configured with a <code>StateListDrawable</code> and does display the highlight.</p>
  
  <p>I would much rather use the <code>ColorStateList</code> than the <code>StateListDrawable</code> as it seems cleaner and involves one less file per item type. Is there something I have missed that would let me use this method? If it isn't intended to work as I am expecting, can someone explain why?</p>