Im making a little shopping list app. In the app, if an item in a list view has been marked as bought it gets crossed off with a line. My problem is that when the list is first displayed, if there are any items that are marked as bought in the list, the first item will appear as being marked as bought(will have a line through it) even if its not.
if no items are marked as bought then the first item displays as it should
Code for my array adapter
public class ListAdapter extends BaseAdapter{
Context context;
ArrayList<List_Item> items;
public ListAdapter(Context context, ArrayList<List_Item> list){
this.context = context;
items = list;
}
@Override
public int getCount() {
if(items != null)
return items.size();
else
return 0;
}
@Override
public Object getItem(int index) {
return items.get(index);
}
@Override
public long getItemId(int index) {
return 0;
}
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
View view = convertView;
Holder holder = new Holder();
if(convertView == null){
view = LayoutInflater.from(context).inflate(R.layout.complex_list_item, parent, false);
}
holder.main = (TextView)view.findViewById(R.id.LItextView1);
holder.second = (TextView)view.findViewById(R.id.LItextView2);
List_Item item = items.get(pos);
holder.main.setText(item.name);
holder.second.setText(item.qtyToBuy + " " + item.unit + "(s) @ $" + item.price
+ " per " + item.unit.toLowerCase());
if(item.bought){
holder.main.setBackgroundResource(R.drawable.strikeout);
}
return view;
}
class Holder{
TextView main;
TextView second;
}
}
Why is this happening? How can i fix this? Any suggestions would be much appreciated.