Note that there are some explanatory texts on larger screens.

plurals
  1. POListView Item Selected State not working
    primarykey
    data
    text
    <p>So I have a ListView and I want to change the color of each items background and text. This ListView is inside a ListFragment. My code inflates the layout in the <code>onCreateView</code> and inflates the layout of each item in the <code>newView</code>. </p> <p>The <code>android:state_pressed="true"</code> is working fine, whenever I press in one item the background changes to that color. But when selecting an item neither the bg color or text color changes, even though I've defined an item with <code>android:state_selected="true"</code> in the selector.</p> <p>Edit: I'm using SDK level 11 (Android 3.0) and a Motorola Xoom.</p> <p>The list fragment layout:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="fill_parent"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>The list item layout:</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="25dp" android:background="@drawable/list_item_bg_selector"&gt; &lt;TextView android:id="@+id/form_title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="@dimen/text_size_xlarge" android:textStyle="bold" android:textColor="@drawable/list_item_text_selector" /&gt; &lt;TextView android:id="@+id/form_subtitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="@dimen/text_size_medium" android:textStyle="normal" android:layout_marginTop="5dp" android:textColor="@drawable/list_item_text_selector" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>The background selector:</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_pressed="true" android:drawable="@color/white" /&gt; &lt;item android:state_selected="true" android:drawable="@drawable/list_item_bg_selected" /&gt; &lt;item android:drawable="@color/list_bg" /&gt; &lt;/selector&gt; </code></pre> <p>The text selector:</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_selected="true" android:drawable="@color/white" /&gt; &lt;item android:drawable="@color/list_text_blue" /&gt; &lt;/selector&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload