我有一個日曆應用程序。我想添加一個顯示當前月份所有事件的列表視圖。遍歷本月獲取所有事件
這是我使用的環路代碼,但它僅顯示該月的最後一個事件,而不是ALL事件:
for(int i = 0; i < _calendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
if(isHoliday(i, month, year, date_value))
{
String date= i + " " + getMonthForInt(month);
CalendarEvents events = new CalendarEvents();
final ArrayList<Event> e = new ArrayList<Event>();
e.addAll(events.eventDetails(hijri_date[1], hijri_date[0]));
for (int j = 0; j < e.size(); j++)
{
Event event = e.get(j);
summary_data = new Summary[]
{
new Summary(date, event.eventdetails)
};
}
}
}
summaryAdapter = new SummaryAdapter(this.getActivity().getApplicationContext(), R.layout.listview_item_row, summary_data);
calendarSummary = (ListView) v.findViewById(R.id.calendarSummary);
calendarSummary.setAdapter(summaryAdapter);
更新的代碼:
CalendarEvents events = new CalendarEvents();
final ArrayList<Event> e = new ArrayList<Event>();
String date;
for(int i = 0; i < _calendar.getActualMaximum(Calendar.DAY_OF_MONTH); i++){
if(isHoliday(i, month, year, date_value))
{
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);
}
}
}
的醫生說,第一天的月份是1:http://developer.android.com/reference/java/util/Calendar.html#DAY_OF_MONTH ...但在你的情況下,似乎第一天將是0.而你會跳過最後一個本月的一天。 –