try going back to using a collection. writing to the database in increments like that is ill-advised.
Here:
public class BrowseCardsAdapter extends CursorAdapter {
private LayoutInflater mInflater = null;
private boolean[] arrCb;
public BrowseCardsAdapter(Context context, Cursor cursor) {
super(context, cursor, true);
mInflater = LayoutInflater.from(context);
arrCb = new boolean[cursor.getCount()];
for (int i = 0; i < arrCb.length; i++) {
arrCb[i] = false;
}
// ^otherwise you can loop through the database (in your activity)
// to fill this array with the correct values and pass it as a parameter
// it'd look like initCb() below;
}
/* private boolean[] initCb() {
Cursor cursor = myDbHelper.query(query statement);
boolean[] arr = new boolean[cursor.getCount()];
int i = 0;
while (cursor.moveToNext()) {
arr[i] = cursor.getString(cursor.getColumnIndex("Have"));
// ^obviously you'd need to convert your value to boolean however
i++;
}
return arr;
}*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return mInflater.inflate(R.layout.list_cards, parent, false);
}
@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
final CheckBox cb_have = (CheckBox) view.findViewById(R.id.cb_have);
TextView cardNumber = (TextView) view.findViewById(R.id.tv_cardnumber);
final String cardNumberText = cursor.getString(cursor.getColumnIndex("CardNumber"));
// final String have = cursor.getString(cursor.getColumnIndex("Have"));
cardNumber.setText(cardNumberText);
cb_have.setChecked(arrCb[cursor.getPosition()]);
cb_have.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (cb_have.isChecked()) {
arrCb[cursor.getPosition()] = true;
} else {
arrCb[cursor.getPosition()] = false;
}
}
});
}
}
two methods of filling the collection are offered. As for your technique, because you are constantly writing to the database, you can't get your values using the old cursor that the adapter was made with. you must re-instantiate the cursor upon each row load. Surely these requirements will make you give it up.