I'm trying to have the background color of rows the user already clicked in a listview changed, to do this I'm using an arraylist saved in SharedPreferences contining the ids of the clicked rows, the problem is that the color changes almost randomly.
code:
private static class ItemHolder {
public TextView TXTTitle, TXTArtist, TXTid, TXTLikes;
public RelativeLayout back;
}
@Override
public View getView(final int position, View view, ViewGroup root) {
ItemHolder holder = new ItemHolder();
if (view == null) {
view = inflater.inflate(R.layout.list_item, root, false);
RelativeLayout _back = (RelativeLayout) view.findViewById(R.id.bg_item);
holder.back = _back;
// paint oldies
Set<String> _set = new HashSet<String>();
_set = Prefs.getStringSet("arrOfOldies", _set);
for(int i = 0; i <= _set.size() ; i++){
if(_set.contains(IDs.get(position))){
//oldie
holder.back.setBackgroundColor(Color.parseColor("#D0D0D0"));
}
}
view.setTag(holder);
} else {
holder = (ItemHolder) view.getTag();
}
}
I think it has something to do with the way a listview is being built, what's the problem and how do I fix it?