I have some problems with a ListView
(it's more of a visual problem), it remembers data such as text values from TextViews
, from the ListView
's rows, but tangles or forgets aspects regarding the TextViews
background color.
The problem shows up only when the ListView
contains many rows. I work with a SimpleCursorAdapter
and a ViewBinder
and want to highlight a TextView
if a condition occurs:
In the ViewBinder
implementation:
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
CharSequence display;
if(view.getId() == R.id.dueDate){
long timestamp = Long.parseLong(cursor.getString(3));
display=DateUtils.getRelativeTimeSpanString(timestamp);
if(timestamp+DaysToMillis(5)> new Date().getTime())
((TextView) view).setBackgroundResource(R.color.marker_red);
((TextView) view).setText(display);
return true;
}
else
return false;
}
So again: when there are many rows the ListView
seems to tangle the background color. Some times when I re-scroll, it change's again the TextView
's background and I can't seem to find the bug or the ListView
's logic.
So, does the setViewValue(..)
method gets called every time before inflating a row? Even if you scroll up or down and a row that's not visible anymore get's visible again? Or the setViewValue(..)
method gets called just for a initial row inflating process and then the created objects are keept in the ListView
's memory?
P.S. The text values from the same TextView
is displayed correctly. I used the same logic in the same setViewValue(..)
method.