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

  • Home
  • SEARCH
  • 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 8182159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:45:58+00:00 2026-06-07T00:45:58+00:00

Is it possible to set different colors for different rows in (dynamic) ListView? I

  • 0

Is it possible to set different colors for different rows in (dynamic) ListView?

I know that I can set background colors e.g. on item click event listener, but I wonder is there a way to set colors dynamically while adding items to adapter?

Isn’t it okay?

itemAdapter = new ArrayAdapter<Bundle>(this, android.R.layout.simple_list_item_1, itemArray) {
         @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View row;
                LayoutInflater inflater = (LayoutInflater)getSystemService
                  (Context.LAYOUT_INFLATER_SERVICE);

                if (null == convertView) {
                    row = inflater.inflate(android.R.layout.simple_list_item_1, null);
                } else {
                    row = convertView;
                }

                row.setBackgroundColor(getItem(position).getInt("color"));
                TextView tv = (TextView) row.findViewById(android.R.id.text1);
                tv.setText(getItem(position).getString("text"));

                return row;
            }
     };
  • 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-07T00:46:01+00:00Added an answer on June 7, 2026 at 12:46 am

    You’ll have to write your own custom ListAdapter. You can simply extend ArrayAdapter if your data is an array or an ArrayList, and override the getView() method. There are an abundance of answers on writing the getView() implementation, but the basic answer for your particular question is that you’ll want to add some logic:

    public View getView(int pos, View convertView, ViewGroup parent) {
    
        //do initialization work with the convertView
    
        if(/*some logic determining whether the view should be colored*/) {
            convertView.setBackgroundColor(myColor);
        } else convertView.setBackgroundColor(defaultColor);
    }
    

    The important thing to remember is to set it back to the other color if it doesn’t meet the logic criteria, as the views are recycled and reused, and may be in an unexpected state otherwise.

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

Sidebar

Related Questions

Using Qt stylesheets, is it possible to set a different background colour for each
So Im setting up a menu that has different background :hover colors. The buttons
I can actually set the background-color of the html tag. I didn't know it
Is it possible to set different texture filtering when working with sprites?
Is it possible to set up a cron job that will execute a php
Is it possible to set env vars in pom.xml that junit tests uses? Netbeans
Is it possible to set z-index that only applies to a certain 'scope', such
I have defined some background colors that I'll be using on my site. So
Possible Duplicate: C# How can I set the color of text in a richtextbox?
I want to know if it's possible to detect available colors in terminal which

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.