如何在SQLite数据库中保存到复选框

如何在SQLite数据库中保存到复选框,sqlite,checkbox,Sqlite,Checkbox,我有一个问题,我想保存我的应用程序数据库中的复选框。但这似乎不起作用。我可以选中复选框,但它不保存? 以下是我迄今为止的代码: 对于复选框: <CheckBox android:id="@+id/checkJob" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="@dimen/text_size

我有一个问题,我想保存我的应用程序数据库中的复选框。但这似乎不起作用。我可以选中复选框,但它不保存? 以下是我迄今为止的代码:

对于复选框:

<CheckBox
        android:id="@+id/checkJob"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="@dimen/text_size"
        android:text="@string/checkjob"
        android:layout_marginTop="18dp"
        android:layout_below="@+id/textViewRef"
        android:layout_alignParentStart="true" />
}

在这个例子中,helper

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(
            "CREATE TABLE " + PERSON_TABLE_NAME +
                    "(" + PERSON_COLUMN_ID + " INTEGER PRIMARY KEY, " +
                    PERSON_COLUMN_CHECKJOB + " TEXT, " +
                    PERSON_COLUMN_JOBNUMBER + " INTEGER)"
    );
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + PERSON_TABLE_NAME);
    onCreate(db);
}

public boolean insertPerson(
                            String checkjobcard,
                            int jobnumber) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(PERSON_COLUMN_CHECKJOB, checkjobcard);

    contentValues.put(PERSON_COLUMN_JOBNUMBER, jobnumber);
    db.insert(PERSON_TABLE_NAME, null, contentValues);
    return true;
}

public int numberOfRows() {
    SQLiteDatabase db = this.getReadableDatabase();
    int numRows = (int) DatabaseUtils.queryNumEntries(db, PERSON_TABLE_NAME);
    return numRows;
}

public boolean updatePerson(Integer id,
                            String checkjobcard,

                            int jobnumber) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(PERSON_COLUMN_CHECKJOB, checkjobcard);

    contentValues.put(PERSON_COLUMN_JOBNUMBER, jobnumber);
    db.update(PERSON_TABLE_NAME, contentValues, PERSON_COLUMN_ID + " = ? ", new String[] { Integer.toString(id) } );
    return true;
}

public Integer deletePerson(Integer id) {
    SQLiteDatabase db = this.getWritableDatabase();
    return db.delete(PERSON_TABLE_NAME,
            PERSON_COLUMN_ID + " = ? ",
            new String[] { Integer.toString(id) });
}

public Cursor getPerson(int id) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res =  db.rawQuery("SELECT * FROM " + PERSON_TABLE_NAME + " WHERE " +
            PERSON_COLUMN_ID + "=?", new String[]{Integer.toString(id)});
    return res;
}

public Cursor getAllPersons() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res =  db.rawQuery( "SELECT * FROM " + PERSON_TABLE_NAME, null );
    return res;
}
}
我不确定我做错了什么?
任何帮助都将不胜感激。
谢谢

选中该复选框时,您希望在数据库中存储什么值?是否选中该复选框?@Keith复选框为真或假,请查看如何获取该值以及此值sitehttps://stackoverflow.com/questions/25261296/how-to-save-a-checkbox-state-in-android-appWhat 值在数据库中存储时,是否希望将其存储在数据库中选中?那么复选框是否选中?@Keith复选框是真是假,请看一下如何获取该值和该值sitehttps://stackoverflow.com/questions/25261296/how-to-save-a-checkbox-state-in-android-app
@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL(
            "CREATE TABLE " + PERSON_TABLE_NAME +
                    "(" + PERSON_COLUMN_ID + " INTEGER PRIMARY KEY, " +
                    PERSON_COLUMN_CHECKJOB + " TEXT, " +
                    PERSON_COLUMN_JOBNUMBER + " INTEGER)"
    );
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + PERSON_TABLE_NAME);
    onCreate(db);
}

public boolean insertPerson(
                            String checkjobcard,
                            int jobnumber) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(PERSON_COLUMN_CHECKJOB, checkjobcard);

    contentValues.put(PERSON_COLUMN_JOBNUMBER, jobnumber);
    db.insert(PERSON_TABLE_NAME, null, contentValues);
    return true;
}

public int numberOfRows() {
    SQLiteDatabase db = this.getReadableDatabase();
    int numRows = (int) DatabaseUtils.queryNumEntries(db, PERSON_TABLE_NAME);
    return numRows;
}

public boolean updatePerson(Integer id,
                            String checkjobcard,

                            int jobnumber) {
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(PERSON_COLUMN_CHECKJOB, checkjobcard);

    contentValues.put(PERSON_COLUMN_JOBNUMBER, jobnumber);
    db.update(PERSON_TABLE_NAME, contentValues, PERSON_COLUMN_ID + " = ? ", new String[] { Integer.toString(id) } );
    return true;
}

public Integer deletePerson(Integer id) {
    SQLiteDatabase db = this.getWritableDatabase();
    return db.delete(PERSON_TABLE_NAME,
            PERSON_COLUMN_ID + " = ? ",
            new String[] { Integer.toString(id) });
}

public Cursor getPerson(int id) {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res =  db.rawQuery("SELECT * FROM " + PERSON_TABLE_NAME + " WHERE " +
            PERSON_COLUMN_ID + "=?", new String[]{Integer.toString(id)});
    return res;
}

public Cursor getAllPersons() {
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor res =  db.rawQuery( "SELECT * FROM " + PERSON_TABLE_NAME, null );
    return res;
}
}