Good day, please i don't know if it might be hard to tell, but could you please have a look at this code and tell me why my list view is behaving funny. like when i click on an item in the list, the state of the item is temporarily copied to another item in the row or even sometimes when i scroll. An example is if one item text is set to green, if i click it, the next item will be set to green and then back to its own state. i followed a tutorial to an extent but i don't know why it behaves this way. please how do i fix this?
heres the code:
public class customCursorAdapter extends SimpleCursorAdapter implements OnCheckedChangeListener {
private int layout;
Context context;
public customCursorAdapter(Context context, int layout, Cursor c, String[]from, int[] to) {
super(context, layout, c, from, to);
this.layout = layout;
this.context = context;
}
@Override
public void bindView(View view, Context context, Cursor c) {
ViewHolder holder;
changeCursor(c);
if(view != null){
holder = new ViewHolder();
//holder.Key_Id = DBAdapter.KEY_ID;
holder.ItemName = (TextView)view.findViewById(R.id.viewNameId);
holder.Status = (TextView)view.findViewById(R.id.viewStatusId);
holder.Date = (TextView)view.findViewById(R.id.viewDateId);
holder.Time = (TextView)view.findViewById(R.id.viewTimeId);
holder.Priority = (Spinner)view.findViewById(R.id.prioritySpinner);
holder.checkbx = (CheckBox)view.findViewById(R.id.checkbox_viewItems_Id);
holder.checkbx.setTag(c.getInt(c.getColumnIndex(DBAdapter.KEY_ID)));
holder.checkbx.setOnCheckedChangeListener(this);
view.setTag(holder);
}else{
holder = (ViewHolder)view.getTag();
}
int namecol = c.getColumnIndex(DBAdapter.NAME);
String name = c.getString(namecol);
holder.viewItemName.setText(name);
int priority = c.getColumnIndex(DBAdapter.PRIORITY);
String prioritystatus = c.getString(priority);
if(prioritystatus.equals("High")){
holder.viewItemName.setTextColor(Color.RED);
}
if(prioritystatus.equals("Low")){
holder.viewItemName.setTextColor(Color.BLUE);
}
if(prioritystatus.equals("Medium")){
holder.viewItemName.setTextColor(Color.GREEN);
}
String startDate = c.getString(c.getColumnIndex(DBAdapter.START_DATE));
holder.Date.setText(startDate);
String startTime = c.getString(c.getColumnIndex(DBAdapter.START_TIME));
holder.Time.setText(startTime);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(context);
final View view = inflater.inflate(layout, parent, false);
}
return view;
}
public Object getItem(int position){
return position;
}
public long getSelectedItemId(long rowId){
return rowId;
}
public int getSelectedItemPosition(int position){
return position;
}