I want to update a column in my table when CheckBox is checked.
I tried this
Log.d("print", " " + res.getString(res.getColumnIndex("name")));
But is giving me this error Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
RecyclerViewAdapter:
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Log.d ("print", "item clicked");
if (checkBox.isChecked()){
databaseHandler.updateHabit(name.getText().toString(), false);
}else{
DatabaseHandler databaseHandler = new DatabaseHandler(ctx);
databaseHandler.updateHabit(name.getText().toString(), true);
}
}
});
DatabaseHandler:
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(Constants.Habit.HABIT_COL_DONE, done);
Cursor res = db.rawQuery("SELECT DESCRIPTION from HABIT_DESCRIPTION WHERE NAME = '" + s + "'", null);
res.moveToFirst();
Log.d("print", " " + res.getString(res.getColumnIndex("name")));
I know it's not updated because when I print my whole table it is the old value.