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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:28:24+00:00 2026-05-24T10:28:24+00:00

I am adding simple data into a listview (name and time) and I want

  • 0

I am adding simple data into a listview (name and time) and I want to be able to alternate between a white and grey background for each table row. I am currently setting the background color in the xml file.

I am using the code from http://saigeethamn.blogspot.com/2010/04/custom-listview-android-developer.html

Thanks

EDIT
my code looks like this

  //R.layout.custom_list_view is just a list view with grey background
   //(I want it white for every other one)
  //On Create section
  setContentView(R.layout.custom_list_view);

    SimpleAdapter adapter = new SimpleAdapter(
            this,
            list,
            R.layout.custom_row_view,
            new String[] {"pen","price"},
            new int[] {R.id.text1,R.id.text2}
            );
    //see function below
    populateList();
    setListAdapter(adapter);
}

static final ArrayList<HashMap<String,String>> list = 
    new ArrayList<HashMap<String,String>>(); 

private void populateList() {
    //for loop would go here
    HashMap<String,String> temp = new HashMap<String,String>();
    temp.put("pen","MONT Blanc");
    temp.put("price", "200.00$");
    list.add(temp);

    HashMap<String,String> temp2 = new HashMap<String,String>();
    temp2.put("pen","Parker");
    temp2.put("price", "400.00$");
    list.add(temp2);
   //theres no place to change the background of my listview

Final Edit. Here is an easy solution http://ykyuen.wordpress.com/2010/03/15/android-%E2%80%93-applying-alternate-row-color-in-listview-with-simpleadapter/
Change SimpleAdapter adapter to the custom SpecialAdapter found in the website. Thank you all for helping

  • 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-24T10:28:25+00:00Added an answer on May 24, 2026 at 10:28 am

    You should do implement custom adapter and set background color there:

    public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            View convertViews;
            if (convertView == null) {
                convertViews = mInflater.inflate(R.layout.startingsquadlistview, null);
                holder = new ViewHolder();
                holder.text = (TextView) convertView.findViewById(R.id.textview);
                convertViews.setTag(holder);
            } else {
                convertViews = convertView;
                holder = (ViewHolder) convertViews.getTag();
            }
    
            if(position % 0) {
                convertView.setBackground(context.getResources().getColor(R.color.col1);
            else
                convertView.setBackground(context.getResources().getColor(R.color.col2);
    
            return convertViews;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want an adaptable database scheme. But still use a simple table data gateway
I've got a view which is adding a bunch of data into a bound
We have a process that is getting data in real time and adding records
Context: I'm working on master adding a simple feature. After a few minutes I
Adding an element to the head of an alist (Associative list) is simple enough:
I have implemented a simple linux shell in c. Now, I am adding some
I'm trying to accomplish simply adding a css class to a div on alternate
I have a couple of databases containing simple data which needs to be imported
I have some data recieved from a simple HTML form like this: $newdata =
I have this code for logging into Google using Simple DOM Parser with curl.

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.