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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:43:49+00:00 2026-05-24T08:43:49+00:00

My vision is to create a color coded listView, where I want to have

  • 0

My vision is to create a color coded listView, where I want to have a slim colored bar in each item’s layout. This bar should be a certain color based on an int I pass to the activity. How do I create such a bar(essentially a filled rectangle) and set its color. Currently, I am using a custom layout for my list and using a SimpleAdapter with an ArrayList.

I know I will have to use

if (integerForColor == someNumber)
    //set the color of the shape, bar

I am sure this is a simple thing that I simply cannot think of at the moment, or must be missing a fundamental. Thank you in advance for your effort.

EDIT 1:

Trying to decode some of the answers that were here, I realized that you guys need my code on how I am building my list:

public class AddScreen extends Activity implements OnClickListener,
    OnItemClickListener, OnItemLongClickListener {
SimpleAdapter adapter;
List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>();
ListView listthings;

public void onCreate(Bundle savedInstanceState) {
from = new String[] { "row_1", "row_2" };
to = new int[] { R.id.row1, R.id.row2 };

adapter = new SimpleAdapter(this, painItems, R.layout.mylistlayout,
            from, to);

listthings.setAdapter(adapter);

}

I have added the getView() Method:

public View getView (int position, View convertView, ViewGroup parent){
    convertView.setBackgroundColor(R.drawable.red);
    return convertView;
      //I have no inflater as of now...
}

enter image description here
EDIT 2: As per @huntsfromshadow ‘s suggestion, I have created a new activity and overridden the getView() method there.

//Imports
 public class Adapter extends SimpleAdapter{

public Adapter(Context context, List<? extends Map<String, ?>> data,
        int resource, String[] from, int[] to) {
    super(context, data, resource, from, to);
    // TODO Auto-generated constructor stub
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
    View row = convertView;
    row.setBackgroundColor(0xFF0000FF);
    return row;

}

}

Unfortunately, it still does not work.

  • 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-24T08:43:50+00:00Added an answer on May 24, 2026 at 8:43 am

    Create a custom adapter and override getView. That is the point where you can do any complicated layout decisions based on values and logic.

    A google search for custom adapter will give you a lot of resources.

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

Sidebar

Related Questions

I'm using IIS 6 on Windows Server 2003. The vision is to create a
My project is a computer vision java application which should implement the following :
I'm new to Silverlight PivotViewer. My goal is to create an image for each
Let's say I have my vision and now my product backlog of items. That
Hello I want to create a simple blog where users can post comments, but
I would like to ask this question to those people who have an experience
I want to create a simple graphical user interface to allow non-technical users to
I want to create an architecture diagram to explain our Software (libraries, Eclipse RCP,
Hoping I can get some architectural advice on this. I have been given the
I am making a strong effort to discipline my projects and create a Vision/Scope

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.