这是 attendance_sheet.xml 文件,其中复选框的数量是通过检索“student_login”表中的学生数来计算的。复选框的名称也应该来自表格。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" XYZ" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=" PQR" />
<Button
android:id="@+id/bUpdateAttendance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit Attendance" />
</TableLayout>
</ScrollView>
在 DbHelper.class
中private static final String STUDENT_TABLE_CREATE = "CREATE TABLE "
+ STUDENT_TABLE + "( s_id INTEGER PRIMARY KEY AUTOINCREMENT , "
+ "s_name TEXT NOT NULL , s_pass TEXT NOT NULL , "
+ "s_roll_no TEXT NOT NULL , " + "s_email TEXT NOT NULL);";
TeacherloggedInPage.java
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.attendancesheet);
Bundle extras = getIntent().getExtras();
if (savedInstanceState == null) {
extras = getIntent().getExtras();
if (extras == null) {
t_id = (String) null;
} else {
t_id = extras.getString("key");
}
} else {
t_id = (String) savedInstanceState.getSerializable("key");
}
UpdateAttendanceButton = (Button) findViewById(R.id.bUpdateAttendance);
UpdateAttendanceButton.setOnClickListener(this);
}
答案 0 :(得分:1)
这是你需要做的,
1)动态创建复选框。
2)根据数据库中的名称,给出复选框名称。
3)将它们添加到您的布局(可能是LinearLayout)
以下是类似的答案How to add CheckBoxes Dynamically
您的布局xml应如下所示
<Linear Layout With orientation Vertical>
<Linear Layout with Orientation Vertical /> // Add CheckBoxes in this Layout, By taking its ID in the code.
<Update BUtton>
</Linear Layout closing for top LL>