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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:57:34+00:00 2026-06-08T01:57:34+00:00

Thanks to help from stackoverflow users I have managed to change colour of one

  • 0

Thanks to help from stackoverflow users I have managed to change colour of one specific row based on some condition. But changing colour doesn’t fully fit my needs and expectations.

So I started looking through web and trying to change it. I want to set text in TextView of specific row. To be able to change row colour I was advised to create personalised SimpleCursorAdapter class as I am getting values into ListView from SQLite using Cursor.

After reading and testing it this is what I came up with:

public class MyCursorAdapter extends SimpleCursorAdapter {
    public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
        super(context, layout, c, from, to);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        super.bindView(view, context, cursor);
        if(cursor.getLong(cursor.getColumnIndex(MyDBAdapter.KEY_PRICE)) == 5)
        {   
            TextView price = (TextView)view.findViewById(R.id.priceInfo);
            price.setText("High");
        }
        else
            view.setBackgroundColor(0x00000000);
    }
}

However, what I am getting now is duplicated text on some rows (there is regularity in it). As I read somewhere, every scroll is refreshing ListView, but how it is possible that when I put in if clause (insted of this TextView) this line: view.setBackgroundColor(SELECTED_COLOR); everything works fine and only this one row had been changed.

Can someone please tell me what I have to do to make it works, or what is wrong in my thinking?

  • 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-08T01:57:36+00:00Added an answer on June 8, 2026 at 1:57 am
    public class MyCursorAdapter extends SimpleCursorAdapter {
        public MyCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
            super(context, layout, c, from, to);
        }
    
        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            super.bindView(view, context, cursor);         
            TextView price = (TextView)view.findViewById(R.id.priceInfo);
            if(cursor.getLong(cursor.getColumnIndex(MyDBAdapter.KEY_PRICE)) == 5)
            {   
                price.setText("High");
                view.setBackgroundColor(/* red color? */);
            }
            else {
                price.setText("");
                view.setBackgroundColor(0x00000000);
            }
        }
    }
    

    Because of “itemrecycling” the view in the bindView has colors and text that is been recycled. You need to assign all properties explicitly for each bindView call that change over different listview items. in this case the backgroundcolor and price label.

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

Sidebar

Related Questions

First, thanks for all the help I've received so far from StackOverflow. I've learned
With the help from good samaritans from stackoverflow, I have come till the following
Thanks to some help on StackOverflow, I am currently animating a path in CAShapeLayer
I have a div:hover script set up http://jsfiddle.net/4wb5P/6/ (with the help of from StackOverflow
I have a show/hide toggle working well in multiple instances (thanks to help here
Thanks to some help I received yesterday I've got some dynamic summing working on
Thanks for your help! I'd like to output all companyName entries that have uploads
Background information: I've searched stackoverflow for a specific solution and couldn't find one that
I have the following regex from here: https://stackoverflow.com/a/10405818/924999 val regex = /https?:\/\/(?:[0-9A-Z-]+\.)?(?:youtu\.be\/|youtube\.com(?:\/embed\/|\/v\/|\/watch\?v=|\/ytscreeningroom\?v=|\/feeds\/api\/videos\/|\/user\S*[^\w\-\s]|\S*[^\w\-\s]))([\w\-]{11})[?=&+%\w-]*/ig;.r I'm attempting
I have made this accordion to teach myself some jQuery with a help of

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.