我需要显示多个数据库表来分隔文本视图。
所以我需要从表中提取所有“约会”并将它们排序以显示在 mainActivity 上的单独文本视图中,例如 txtMonday、txtTuesday、txtWednesday
该数据库旨在存储日期以及其他详细信息:
private static final String DATABASE_CREATE =
"create table " + TABLE_AP + "(" + COLUMN_ID + " integer primary key autoincrement, "
+ COLUMN_DAY + " text not null, "
+ COLUMN_TIME + " text not null, "
+ COLUMN_DURATION + " text not null, "
+ COLUMN_DESCRIPTION + " text not null);";
这就是我尝试通过 MainActivity 调用它的方式:(我也将使用 onCreate 调用它)
public void onResume (){
APData = new AppointmentDataSource(this);
APData.open();
List<Appointment> appointments = APData.retrieveAllAppointments();
APData.close();
预约资料来源:
public List<Appointment> retrieveAllAppointments () {
List<Appointment> appointments = new ArrayList<Appointment>();
Cursor cursor = database.query(MySQLiteHelper.TABLE_AP, , null, null, null, null, null);
cursor.moveToFirst();
while (!cursor.isAfterLast()) {
Appointment ap = cursorToBk(cursor);
appointments.add(ap);
cursor.moveToNext();
}
cursor.close();
return appointments;
}
同样在这些日子里,我使用单选按钮在星期一/星期二/星期三/星期四/星期五之间进行选择,所以我将这一天存储为:
createButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
findRadioGroup = (RadioGroup) findViewById(R.id.radioDay);
int selectedId = findRadioGroup.getCheckedRadioButtonId();
radioButton = (RadioButton) findViewById(selectedId);
String day=radioButton.getText().toString();
String time=txtTime.getText().toString();
String duration=txtDuration.getText().toString();
String description=txtDescription.getText().toString();
APData.insert(day, time, duration, description);
APData.close();
finish();
}
});
以及它们的 XML/字符串:
<string name="RadioMon">Mon</string>
<string name="RadioTue">Tue</string>
<string name="RadioWed">Wed</string>
<string name="RadioThu">Thur</string>
<string name="RadioFri">Fri</string>