gpt4 book ai didi

java - 循环显示最后一个日期值

转载 作者:行者123 更新时间:2023-12-02 07:34:18 24 4
gpt4 key购买 nike

我有一个日历应用程序。我想循环当前月份以获取所有事件。唯一的问题是所有事件的最后一个事件的日期显示。

似乎所有事件的日期值都被最后一个事件的日期值替换。

   CalendarEvents events = new CalendarEvents();
final ArrayList<Event> e = new ArrayList<Event>();


for(int i = 0; i < _calendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
if(isHoliday(i, month, year, date_value))
{
String date = i + "-" + month + "-" + year;

e.addAll(events.eventDetails(month, day));
summary_data = new Summary[e.size()];

for (int j = 0; j < e.size(); j++)
{

Event event = e.get(j);
summary_data[j] = new Summary(date, event.eventdetails);
}
}
}

最佳答案

是的,考虑到程序的逻辑,这是预期的。

你循环过这些日子。对于每一天,您将当天的事件添加到事件列表中(命名不当的 e 列表)。对于每一天,您循环遍历此列表中的每个事件(因此包含从月初到当天的所有事件),并创建一个 Summary 实例数组,每个摘要包含当天的日期以及事件的详细信息(无论是过去的事件还是当天的事件)。

事件列表似乎没有用。我会简单地使用一个摘要列表:

final List<Summary> summaries = new ArrayList<Summary>();

// loop through the days
for (int i = 0; i < calendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++) {
if (isHoliday(i, month, year, date_value)) {
String date = i + "-" + month + "-" + year;
// loop through the events of the day
for (Event event : events.eventDetails(month, day)) {
// add a summary for the current day and the current event of the day
summaries.add(new Summary(date, event.eventdetails));
}
}
}

关于java - 循环显示最后一个日期值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12479280/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com