私の Android アプリケーションには、Appointment
予定に関連する情報を含むオブジェクトのリストがあります。次にListView
、これらの予定の選択が時間順にソートされてデータが取り込まれます。
予定の間にギャップがある「自由時間」の予定を挿入できるようにするために、このリストビュー用に独自のカスタム アダプターを作成しました。
これまでの私のコードは次のとおりです。
ArrayList<Appointment> appointments = new ArrayList<Appointment>();
// populate arraylist here
ListIterator<Appointment> iter = appointments.listIterator();
DateTime lastEndTime = new DateTime();
int count = 0;
while (iter.hasNext()){
Appointment appt = iter.next();
lastEndTime = appt.endDateTime;
// Skips first iteration
if (count > 0)
{
if (lastEndTime.isAfter(appt.startDateTime))
{
if (iter.hasNext())
{
Appointment freeAppt = new Appointment();
freeAppt.isFreeTime = true;
freeAppt.subject = "Free slot";
freeAppt.startDateTime = lastEndTime;
freeAppt.endDateTime = lastEndTime.minusMinutes(-60); // Currently just set to 60 minutes until I solve the problem
iter.add(freeAppt);
}
}
}
count++;
}
DiaryAdapter adapter = new DiaryAdapter(this, R.layout.appointment_info, appointments);
私が抱えている問題は論理的なものです。私は解決策を見つけようと頭を悩ませてきましたが、Java の知識が不足しているため、ここで少し足を引っ張っているようです。
「自由時間」の予定がいつ終了するかを知るには、次の「実際の」予定がいつ始まるかを知る必要があります。しかし、イテレータの次のサイクルまでその情報を取得することはできません。その時点までに、「空き時間」の予定はコンテキストから外れます。
どうすればこの問題を解決できますか?