Note that there are some explanatory texts on larger screens.

plurals
  1. PODrawable selector not working in Jelly Bean
    primarykey
    data
    text
    <p>I have a drawable selector as a background for each item in a <code>ListView</code> to highlight the selected row. Eveything works fine in Ice Cream Sandwich, but doesn't seem to work in Jelly Bean. Can't find any documentation saying what changes could have caused it to stop working and what I need to do to fix it.</p> <p>By not working, I mean when I click on a row in the <code>ListView</code> the item's background color isn't turning the <code>@color/blue</code> color, but it does in ICS.</p> <p>This is the selector code I'm using (listing_selector.xml):</p> <pre><code>&lt;selector xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:state_focused="true" android:drawable="@color/blue" /&gt; &lt;item android:state_pressed="true" android:drawable="@color/blue" /&gt; &lt;item android:state_activated="true" android:drawable="@color/blue_selected" /&gt; &lt;item android:state_selected="true" android:drawable="@color/blue_selected" /&gt; &lt;item android:drawable="@android:color/transparent" /&gt; &lt;/selector&gt; </code></pre> <p>This is the layout of the <code>ListView</code> item:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="horizontal" android:background="@color/listing_selector" &gt; &lt;TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p>This the blue color resource:</p> <pre><code>&lt;resources&gt; &lt;color name="blue"&gt;#ff33b5e5&lt;/color&gt; &lt;/resources&gt; </code></pre> <p><strong>UPDATE 1:</strong></p> <p>Tried moving the selector from the <code>color</code> folder to the <code>drawable</code> folder and updating the code to this:</p> <pre><code>android:background="@drawable/listing_selector" </code></pre> <p><strong>UPDATE 2:</strong></p> <p>Also, on the <code>ListView</code>, tried adding this:</p> <pre><code> &lt;ListView android:id="@android:id/list" android:layout_width="wrap_content" android:layout_height="fill_parent" android:listSelector="@drawable/listing_selector" /&gt; </code></pre> <p><strong>UPDATE 3:</strong></p> <p>I thought it might be something in my code, but I removed all the code from <code>onListItemClick</code> of the <code>ListView</code> and still the <code>selector</code> isn't working.</p> <p><strong>UPDATE 4:</strong></p> <p>I've narrowed it down to <code>state_selected</code> or <code>state_activated</code> not working as, <code>state_pressed</code> seems to be working</p> <p><strong>UPDATE 5:</strong></p> <p>I think I was mistaken. I don't think the selector is being recognized, at all. I was confusing the built-in <code>ListView</code> highlighting as my selector. I'm now wondering if it has something to do with the way my project is setup. I have the selector in a Library Class. Maybe something changed with that from ICS to JB, however moving the selector to my app's project didn't seem to fix it.</p> <p><strong>UPDATE 6:</strong></p> <p>Ok, after some more hair pulling, I've narrowed it down, again, to either <code>state_selected</code> or <code>state_activated</code> not being recognized, as changing the color for <code>state_pressed</code> does work, which means my selector is being recognized. From the comments in seems to be something with my app specifically as others have been able to get selectors working with Jelly Bean.</p> <p>Though something else that is interesting is that changing the <code>drawable</code> value for the default state is not recognized. Where I have <code>color/transparent</code>, I would think changing that to a color would cause the listing to change to that color, but it doesn't.</p> <p>Also, this isn't working in ICS either.</p> <p><strong>UPDATE 7:</strong></p> <p>After even more hair pulling, I've discovered that long-pressing on a menu item results in that item's color being changed. Just clicking on an item still does not work. Not even sure what the means.</p> <p>** Final Update:**</p> <p>I give up, I removed the selector and am just refreshing the <code>ListView</code> on click and remembering the position clicked and highlighting it from code. Not ideal, but not worth the effort to try to fix.</p>
    singulars
    1. This table or related slice is empty.
    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