Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8562075
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:39:00+00:00 2026-06-11T16:39:00+00:00

I have a drawable selector as a background for each item in a ListView

  • 0

I have a drawable selector as a background for each item in a ListView 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.

By not working, I mean when I click on a row in the ListView the item’s background color isn’t turning the @color/blue color, but it does in ICS.

This is the selector code I’m using (listing_selector.xml):

<selector xmlns:android="http://schemas.android.com/apk/res/android" >

   <item android:state_focused="true" android:drawable="@color/blue" />

   <item android:state_pressed="true" android:drawable="@color/blue" />

   <item android:state_activated="true" android:drawable="@color/blue_selected" />  

   <item android:state_selected="true" android:drawable="@color/blue_selected" />

   <item android:drawable="@android:color/transparent" />

</selector>

This is the layout of the ListView item:

<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"    
>

    <TextView 
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true" 
    />

</RelativeLayout>

This the blue color resource:

<resources>
    <color name="blue">#ff33b5e5</color>       
</resources>

UPDATE 1:

Tried moving the selector from the color folder to the drawable folder and updating the code to this:

android:background="@drawable/listing_selector"

UPDATE 2:

Also, on the ListView, tried adding this:

    <ListView android:id="@android:id/list"
        android:layout_width="wrap_content"  
        android:layout_height="fill_parent" 
        android:listSelector="@drawable/listing_selector"   
    />

UPDATE 3:

I thought it might be something in my code, but I removed all the code from onListItemClick of the ListView and still the selector isn’t working.

UPDATE 4:

I’ve narrowed it down to state_selected or state_activated not working as, state_pressed seems to be working

UPDATE 5:

I think I was mistaken. I don’t think the selector is being recognized, at all. I was confusing the built-in ListView 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.

UPDATE 6:

Ok, after some more hair pulling, I’ve narrowed it down, again, to either state_selected or state_activated not being recognized, as changing the color for state_pressed 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.

Though something else that is interesting is that changing the drawable value for the default state is not recognized. Where I have color/transparent, I would think changing that to a color would cause the listing to change to that color, but it doesn’t.

Also, this isn’t working in ICS either.

UPDATE 7:

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.

** Final Update:**

I give up, I removed the selector and am just refreshing the ListView on click and remembering the position clicked and highlighting it from code. Not ideal, but not worth the effort to try to fix.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:39:02+00:00Added an answer on June 11, 2026 at 4:39 pm

    Okay, i think its an issue with your selector. Try removing the state_focused and the state_activated. You could try this for your selector:

    <!-- Disabled State -->
    <item
        android:state_enabled = "false"
        android:state_focused = "true"
        android:state_pressed = "true"
        android:drawable="@android:color/transparent">
    </item>
    <item
        android:state_enabled = "false"
        android:state_focused = "true"
        android:drawable="@android:color/transparent">
    </item>
    
    <!-- Pressed State -->
    <item
        android:state_pressed = "true"
        android:state_focused = "true">
        <shape>
            <solid android:color="@color/blue"/>
        </shape>
    </item>
    <item
        android:state_pressed = "true"
        android:state_focused = "false">
        <shape>
            <solid android:color="@color/blue"/>
        </shape>
    </item>
    
    <!-- Normal State -->
    <item
        android:drawable="@android:color/transparent">
    </item>
    

    I found that I needed to use a shape object too instead of android:drawable, because on pre-ICS phones, the whole list will be highlighted that color instead of the pressed list item.

    You can add in your state_selected code too, but I’m not sure how it will be used. Check out the default selector code for jelly bean for the states they use: list_selector_background.xml.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to apply a custom background to each Listview item via the
I have to make another highlight color for ListView item. I use custom adapter
I have a customized ListView that each row of the list is composed by
I have a ListView , and for each row of the ListView I have
I have the following code in a drawable bitmap xml file. And the background
I have a clickable TextView with a drawable as its background. I'm looking for
I have a custom button in an activity. It works fine. I hit back,
I have one ImageButton in my xml layout like that : <ImageButton android:id=@+id/tabsButton android:background=@drawable/button
So I have a ListView and I want to change the color of each
i have a ListView with a custom row: detail_row1.xml <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.