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 3492282
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:44:22+00:00 2026-05-18T11:44:22+00:00

I have a list view and an adapter that sets alternating background colors to

  • 0

I have a list view and an adapter that sets alternating background colors to the list items (“zebra” list style):

public View getView(final int position, View convertView, ViewGroup parent) {
    int colorPos = position % colors.length;
    ...
    convertView.setBackgroundColor(colors[colorPos]);
    return convertView;
}

But now, when i select an item using scroll wheel, or when I click an item, the original colors for selecting/clicking do not override my custom backgrounds (I can see the original color below the one I set).

How can I set the original colors for these states?

  • 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-05-18T11:44:23+00:00Added an answer on May 18, 2026 at 11:44 am

    I think the easiest way is to create two selectors which are used as the background resources, with transparent color in the state_selected mode:
    (res/drawable/alterselector1.xml:)

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_selected="true"
            android:drawable="@drawable/transparent" />
        <item android:state_pressed="true"
            android:drawable="@drawable/transparent" />
        <item android:state_selected="false"
            android:drawable="@drawable/altercolor1"/>
    
    </selector>
    

    (res/drawable/alterselector2.xml:)

    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_selected="true"
            android:drawable="@drawable/transparent" />
        <item android:state_pressed="true"
            android:drawable="@drawable/transparent" />
        <item android:state_selected="false"
            android:drawable="@drawable/altercolor2"/>
    </selector>
    

    (res/values/colors.xml:)

    <resources>
        <drawable name="transparent">#00ffffff</drawable>
        <drawable name="altercolor1">#ffffffff</drawable>
        <drawable name="altercolor2">#ff000000</drawable>
    </resources>
    

    Then you set the backgrounds in the getView method of the adapter with the setBackgroundResource method:

    if (position % 2 == 0){
        reusableView.setBackgroundResource(R.drawable.alterselector1);
    } else {
        reusableView.setBackgroundResource(R.drawable.alterselector2);
    }
    

    Now when you select a row, your background don’t hide the original selector behind.

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

Sidebar

Related Questions

We have created a new List View Style that shows thumbnails from a picture
I have created a list view that displays the names and dates of items
I have a list view that is periodically updated (every 60 seconds). It was
I have a view that has a list of jobs in it, with data
I have implemented a custom list view which looks like the twitter timeline. adapter
I have a ListView powered by a custom adapter that dynamically changes the background
i have a list view and custom list adapter for it. There are various
I have a list view control which at the moment only allows one item
I currently have a list view which has several rows of data and I
I have a databound list view and can set all the column widths manually

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.