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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T08:38:45+00:00 2026-06-01T08:38:45+00:00

In my app I show some info and depending on the value I change

  • 0

In my app I show some info and depending on the value I change the color of the textView.

public class DealsAdapter extends CursorAdapter {
    private Cursor mCursor;
    private Context mContext;
    private final LayoutInflater mInflater;

    public DealsAdapter(Context context, Cursor cursor) {
        super(context, cursor, true);
        mInflater = LayoutInflater.from(context);
        mContext = context;
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        final View view = mInflater.inflate(R.layout.deals_row, parent, false);
        return view;
    }

    @Override
    public void bindView(View row, Context context, Cursor cursor) {
         Text View percent = (TextView) row.findViewById(R.id.tvPercent);
          percent.setText(cursor.getString(cursor
                .getColumnIndex(DBHelper.D_PERCENT)));
          float percentV = cursor.getFloat(cursor
                .getColumnIndex(DBHelper.D_PERCENT));
          if (percentV >= 41 && percentV <= 70) {
            // Orange
            percent.setTextColor(Color.parseColor("#F58549"));
        } else if (percentV >= 71) {
            // Green
            percent.setTextColor(Color.parseColor("#17D11D"));
        }
}

The problem is after i scroll up and down the colors start getting mixed up but the values stay the same.

Any advice?

Edit: In the xml I set the color to red and only change if needed.

  • 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-01T08:38:46+00:00Added an answer on June 1, 2026 at 8:38 am

    You aren’t explicitly setting a colour if percentV < 41. This means the item will retain whatever colour that view had previously, giving unpredictable results.

    This is because each item’s View may be reused for performance reasons. If you scroll one item off the top of the screen, the same View may be used for the new item appearing at the bottom of the screen, to save the cost of inflating a new one each time. You have to explicitly set the default colour in bindView(), or else the View will retain whatever colour it had for the last item it contained.

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

Sidebar

Related Questions

I have an app that will show some images using UIImageView, now I want
In my app I have need to trigger show some custom view when status
I am switching to map app from my app to show the location,can some
i have to build an small app in order to show some data from
I'm making an app which for now, parses an url and takes some info
Within a public class that doesn't extend any other class I'm doing some evaluation
I am developing an app which will show some information in a detailview which
I'm building an app and i've got a list loaded with some info from
Our goal is simple for an iPhone app: show a splash page then hide
Problem: iPhone screen mirroring & a dedicated external view of my app show an

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.