Reputation: 7519
I have a calendar app. I want to loop through the current month to get all the events. The only problem is that the date displays of the last event for all the events.
It seems the date value of all the events is replaced by the date value of the last event.
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);
}
}
}
Upvotes: 0
Views: 309
Reputation: 691913
Yes, that's expected given the logic of the program.
You loop through the days. For each day, you add the events of the day to a list of events (the badly named e
list). And for each day, you the loop through each events in this list (which thus contains all the events from the start of the month until the current day), and create an array of Summary
instances, each summary containing the date of the current day, and the details of the event (whether it's a past event or an event of the current day).
The list of events doesn't seem useful. I would simply use a list of summaries:
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));
}
}
}
Upvotes: 2