I've got a ListView that displays some results from the DB through a CursorAdapter...Title, text and a flag to indicate if the user has already viewed that item (by taking them to another screen)... Basically if the DB "visited" value is 0 it needs to display a small "new" icon next to the item...If not it shouldn't show any icon...
The problem is that when it loads the list it assigns the flag seemingly at random...The visited ones don't have the flag, but some unvisited ones miss the flag too...
I've tried moving the "visited" check between BindView and NewView but I get the same results...
My adapter:
public class newsAdapter extends CursorAdapter{
public newsAdapter(Context context, Cursor cursor){
super(context, cursor);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView title = (TextView) view.findViewById(R.id.newsItemTitle);
TextView text = (TextView) view.findViewById(R.id.newsItemText);
ImageView newflag = (ImageView) view.findViewById(R.id.newsNewFlag);
if(cursor.getInt(cursor.getColumnIndex("visited")) == 0){
Log.i("extra","Not visited yet");
newflag.setImageResource(R.drawable.icon_new);
}
title.setText(cursor.getString(cursor.getColumnIndex("title")));
text.setText(cursor.getString(cursor.getColumnIndex("text"))); iv);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.news_item, parent, false);
return view;
}
}
I'm sure the data is correct in the DB... Thanks in advance!