Add this code to the OnCreate method:
SQLiteOpenHelper dbh = new StudentsDbHelper(this);
try {
db = dbh.getWritableDatabase();
}
catch(SQLiteException e) {
Toast toast = Toast.makeText(this,
"Database not created.", Toast.LENGTH_LONG);
}
// System.out.println("In OnCreate");
edtxtName = findViewById(R.id.edtxt_name);
edtxtGrade = findViewById(R.id.edtxt_grade);
edtxtGender = findViewById(R.id.edtxt_gender);
txtName = findViewById(R.id.txt_name);
txtGrade = findViewById(R.id.txt_grade);
txtGender = findViewById(R.id.txt_gender);
cursor = db.query("students",
new String[ ] {"name", "grade", "gender"},
null, null, null, null, null);
Add lines to onClickEnterData that will
get the data from the
EditText widgets:
String name = edtxtName.getText( ).toString( );
int grade = Integer.parseInt(edtxtGrade.getText( ).toString( ));
String gender = edtxtGender.getText( ).toString( );
set up a ContentValues object:
ContentValues studentValues = new ContentValues( );
insert the data into the ContentValues object:
studentValues.put("name", name);
studentValues.put("grade", grade);
studentValues.put("gender", gender);
insert the data into the SQL students table:
db.insert("students", null, studentValues);
clear the data from the EditText widgets:
edtxtName.setText("");
edtxtGrade.setText("");
edtxtGender.setText("");
set up a cursor to navigate the students table:
cursor = db.query("students",
new String[ ] {"name", "grade", "gender"},
null, null, null, null, null);
The null arguments correspond to these parameters:
selection selectionArgs groupBy
having orderBy