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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:43:43+00:00 2026-06-17T04:43:43+00:00

I need to have even rows as white and odd rows sd grey in

  • 0

I need to have even rows as white and odd rows sd grey in my ListView (using ArrayAdapter to populate it). I can’t use different layouts with different background color because if I do the selection doesn’t work. What I do is just use this piece of code in my getView() to check if row is odd or even and apply background depending on condition:

if (position % 2 == 0) {
convertView.setBackgroundDrawable(getResources().getDrawable(R.drawable.dark_item_background));}

But this doesn’t work as expected because the only first visible rows are of correct background color. After scrolling to the bottom (I assume because of recycling mechanism) I have very weird behavior and don’t understand why. Here is what I have for the first items (correct case):

enter image description here

Here is what I have after scrolling:

enter image description here

  • 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-17T04:43:44+00:00Added an answer on June 17, 2026 at 4:43 am

    In getView() objects are reused for better performance.Thats why you get this weird behavior. To solve your problem just add if – else

    if (position % 2 == 0) {
       convertView.setBackgroundDrawable(getResources().getDrawable(R.drawable.dark_item_background));
    } else {
       convertView.setBackgroundDrawable(getResources().getDrawable(R.drawable.light_item_background));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to do something I don't even know if is possible.. We have
I have two tables which I need to select all rows from where the
I need to develop an app that is using multithreading. Basicly, I have a
I have a query where I need to batch insert rows into a table
I have a method to process the rows from a datatable using multiple threads,
I have a typical situation, where I need pull multiple rows from mysql by
i have this code in my index.html: <div id=users-list> <tr class=<%= cycle('odd', 'even') %>
I have a, probably unique situation in which I need to use a single
I have a bit of PHP code which I need to return an even
I'm generating an excel file using Apache POI 3.8 , and have the need

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.