This question has already been answered:
public class CustomAdapter extends SimpleCursorAdapter {
private DatabaseHelper databaseHelper; private SQLiteDatabase sqLiteDatabase; private static final String TAG = "myLogs"; private LayoutInflater mInflater; public CustomAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); } @Override public void bindView(View view, final Context context, Cursor cursor) { super.bindView(view, context, cursor); mInflater = LayoutInflater.from(context); CheckBox checkBox=(CheckBox)view.findViewById(R.id.checkBox); checkBox.setText("Виконав"); final long id=cursor.getLong(cursor.getColumnIndex(RECORD_ID)); final long idch=cursor.getLong(cursor.getColumnIndex(CHECKBOX)); checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (buttonView.isChecked()) { databaseHelper = new DatabaseHelper(context); sqLiteDatabase = databaseHelper.getWritableDatabase(); String cb = "1"; ContentValues contentValues = new ContentValues(); contentValues.put(CHECKBOX, cb); sqLiteDatabase.update(DatabaseHelper.DATABASE_TABLE, contentValues, DatabaseHelper.RECORD_ID + " = " + id, null); Log.d(TAG, "1\nНачало\nid" + String.valueOf(id) + "\nidch" + String.valueOf(idch) + "\nконец\n"); } else { databaseHelper = new DatabaseHelper(context); sqLiteDatabase = databaseHelper.getWritableDatabase(); String cb = "0"; ContentValues contentValues = new ContentValues(); contentValues.put(CHECKBOX, cb); sqLiteDatabase.update(DatabaseHelper.DATABASE_TABLE, contentValues, DatabaseHelper.RECORD_ID + " = " + id, null); Log.d(TAG, "0\nНачало\nid" + String.valueOf(id) + "\nidch" + String.valueOf(idch) + "\nконец\n"); } } }); } @Override public View newView(final Context context, Cursor cursor, ViewGroup parent) { mInflater = LayoutInflater.from(context); final View view = mInflater.inflate(R.layout.view_record, parent, false); CheckBox checkBox=(CheckBox)view.findViewById(R.id.checkBox); final long idch=cursor.getLong(cursor.getColumnIndex(CHECKBOX)); switch ((int)idch){ case 1: checkBox.setChecked(true); break; case 0: checkBox.setChecked(false); break; } return view; } }
What would not explain for a long time https://www.youtube.com/watch?v=oHD7y_fUglA&feature=youtu.be I don't even have any ideas why so, I am new. And yes, the necessary entries are written to the database.