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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:11:44+00:00 2026-05-18T21:11:44+00:00

Hey everyone I’m not a professional coder by any stretch, but I’ve been playing

  • 0

Hey everyone I’m not a professional coder by any stretch, but I’ve been playing around with a simple to-do list to learn the basics of android development.

I’ve been able to get just about everything I want working, but there is one problem with my listview that has me totally stumped. I’ve extended SimpleCursorAdapter in order to format the data coming from my sqlite database and change the color of the duedate text based on whether or not the duedate has expired. The formatting works flawlessly, but I’m getting some odd results with the colors.

The first few entries in the listview look as I expect them to, but as I scroll down, inconsistencies start popping up where items with no due date set will be colored red or green. The more I scroll up and down in the list, the more inconsistencies appear until eventually every row is colored whether it should be or not.

Can someone help me understand what is going on here? Please see my custom adapter below.

public class ProAdapter2 extends SimpleCursorAdapter {
  private static int[] TO = {R.id.priority, R.id.projectname, R.id.duedate};
  private static String[] FROM = {"priorities", "projectName", "dueDate"};
  private Context context;
  private int layout;

  //constructor
  public ProAdapter2(Context context, int layout, Cursor c) {
    super(context,layout, c, FROM, TO);
    this.context=context;
    this.layout = layout;
  }    

  @Override
  public View newView(Context context, Cursor curso, ViewGroup parent){
    Cursor c = getCursor();
    final LayoutInflater inflater = LayoutInflater.from(context);
    View v = inflater.inflate(layout, parent, false);
    TextView txtName = (TextView) v.findViewById(R.id.projectname);
    txtName.setText(c.getString(1));
    TextView txtPriority = (TextView) v.findViewById(R.id.priority);
    txtPriority.setText(c.getString(2));

    return v;
  }   

  @Override
  public void bindView(View v, Context context, Cursor c) {
    TextView txtDueDate = (TextView) v.findViewById(R.id.duedate);
    TextView txtDueDateLabel = (TextView) v.findViewById(R.id.duedate_label);
    TextView txtPriority = (TextView) v.findViewById(R.id.priority);
    TextView txtPriorityLabel = (TextView) v.findViewById(R.id.priority_label);
    TextView txtName = (TextView) v.findViewById(R.id.projectname);

    LinearLayout pridate = (LinearLayout) v.findViewById(R.id.pridate);

    String dueDate = c.getString(3);
    String cDate = c.getString(4);
    String dueDateFormated;

     MyTime t = new MyTime();
     Long cTimeLong = c.getLong(6);
     Long dTimeLong = c.getLong(5);

     dueDateFormated = t.getFormatedTime(c.getString(3));     
     txtDueDate.setText(dueDateFormated);

     if (c.getInt(5)==0){
        txtDueDate.setText("Not Set");
     }
     else if (cTimeLong < dTimeLong){       
         txtDueDate.setTextColor(Color.GREEN);
     }
     else if (cTimeLong > dTimeLong){
        txtDueDate.setTextColor(Color.RED);
    }
  }
}

image
https://i.stack.imgur.com/bt4Z8.png

  • 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-18T21:11:45+00:00Added an answer on May 18, 2026 at 9:11 pm

    The simplest solution would be to add the following after txtDueDate.setText("Not Set");:

    txtDueDate.setTextColor(Color.BLACK);
    

    The reason is that a ListView recycles the View objects you create in the newView method.

    So when bindView is called, the v parameter isn’t always a shiny-new View object, but in fact one from the top of the list that isn’t visible any more, and so previously had green or red text.

    So you need to make sure you explicitly set all the properties you require, including the text colour.

    Aside from that, there are further optimisations you can make. For example, you shouldn’t be calling setText in your newView method — you should only do this in the bind method.

    For some good info about how the ListView works, you can watch this talk or look at the PDF slides:
    http://www.google.com/events/io/2010/sessions/world-of-listview-android.html

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

Sidebar

Related Questions

Hey everyone... I'm not too familiar with PHP... but I have PHP code that
Hey everyone, I am trying to run the following program, but am getting a
Hey everyone, I've been creating a little chat bot (for fun and practice). I
Hey everyone. While I'm trying to learn some PHP and mySQL, I ran into
Hey everyone. I have a fair amount of experience developing iOS apps, but nothing
Hey everyone, I'm using Virtual PC and working with a virtual hard disk (*.vhd)
Hey everyone. I'm trying to make a swing GUI with a button and a
Hey everyone, I'm working on a PHP application that needs to parse a .tpl
Hey, I've been developing an application in the windows console with Java, and want
Hey peoples, I've been studying Java for a couple of weeks, and have decided

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.