i have a listview which is generated via a custom cursoradapter
everything is working fine, except when i scroll up and down through the list, some of the textview’s are changing to GREEN randomly.
heres my code which generates the listview:
private class AchievementAdapter extends CursorAdapter {
public AchievementAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View v, Context context, Cursor cursor) {
TextView tv = (TextView) v.findViewById(R.id.achView1);
if(cursor.getString(cursor.getColumnIndex("completed")).equals("yes")) {
tv.setText(cursor.getString(cursor.getColumnIndex("name"))+" (completed)");
tv.setTextColor(Color.GREEN);
}
else {
tv.setText(cursor.getString(cursor.getColumnIndex("name")));
}
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.achievements_item, parent, false);
return v;
}
}
i read something about setcachecolorhint, but the method does not apply to a textview. how do i fix this so it stops changing textview colors randomly when i scroll?
You should set textView color to normal in the
elsestatement like:Hope this helps