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.

Reported as a duplicate by participants YurySPb , Vladyslav Matviienko , Qwertiy , aleksandr barakin , D-side 30 Mar '16 at 11:37 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

  • one
    Exactly such questions as this one is probably about a dozen here - Vladyslav Matviienko
  • Do you guys even read the code? In essence, the question is whether you write the checkbox values ​​to the database. - Chaynik
  • In the database are written. - LeShChEnKoUa

0