【发布时间】:2019-03-29 03:15:45
【问题描述】:
我正在创建事件应用程序,其中列出了所有事件。
我有一个问题,当活动结束时,它仍然保持不变,因为如果下一个活动是在一周之后,它会按时间排序。像这样:
所以,结束的事件,需要往下走,还要按日期排序。
我该怎么做?
我尝试按日期和布尔值分别排序,但失败了。 还是我需要为已结束的事件和即将到来的事件创建两个数组列表?
如果有人知道如何做到这一点,请告诉我,你拯救了我的一天。
我的代码,现在排序:
Collections.sort(eventsList, new Comparator<TimetableEvent>() {
@Override
public int compare(TimetableEvent arg0, TimetableEvent arg1) {
SimpleDateFormat format = new SimpleDateFormat(
"dd.MM.yyyy' klo 'HH.mm");
int compareResult = 0;
try {
Date arg0Date = format.parse(arg0.getDateTime());
Date arg1Date = format.parse(arg1.getDateTime());
compareResult = arg0Date.compareTo(arg1Date);
} catch (ParseException e) {
e.printStackTrace();
compareResult = arg0.getDateTime().compareTo(arg1.getDateTime());
}
return compareResult;
}
});
【问题讨论】: