i'm trying to save user data to a database. There is 2 checkboxes teacher and student but there is only one table. the table is looks like this
private static final String CREATE_TABLE_USER ="CREATE TABLE " + TABLE_USER + " ( " +
USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
NAME + " TEXT, " +
PASSWORD + " TEXT, " +
TYPE + " TEXT " + ")";
this is the insert method
public boolean registeruser(String name, String password, String type) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(NAME, name);
contentValues.put(PASSWORD, password);
contentValues.put(TYPE, type);
long result = db.insert(TABLE_USER, null, contentValues);
return result != -1;
}
when i'm calling the registeruser
db function i have to declare a type but the type is 2 checkboxes how can i mention it in here
The method isChecked()
of the CheckBox
class returns true
or false
.
I guess you want to save "Teacher"
or "Student"
in the table:
db.registeruser(
username.getText().toString(),
password.getText().toString(),
teacher.isChecked() ? "Teacher" : (student.isChecked() ? "Student" : "N/A")
);