テキストビューを分離するために複数のデータベース テーブルを表示する必要があります。
したがって、テーブルからすべての「予定」を取得し、それらを並べ替えて、txtMonday、txtTuesday、txtWednesday などの mainActivity の個別のテキストビューに表示する必要があります。
データベースは、その日をその他の詳細とともに保存するように設計されています。
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();
AppointmentDataSource:
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>