我有这个问题,事件在一行中出现3次 当我使用这种方法时,不会出现
private List<WeekViewEvent> getEventsForMonth(int year, int month) {
List<WeekViewEvent> tempList = new ArrayList<WeekViewEvent>();
for (WeekViewEvent weekViewEvent : events) {
if (weekViewEvent.getStartTime().get(Calendar.MONTH) == month && weekViewEvent.getStartTime().get(Calendar.YEAR) ==
year) {
tempList.add(weekViewEvent);
}
}
return tempList;
}
我在这里使用
MonthLoader.MonthChangeListener mMonthChangeListener = new MonthLoader.MonthChangeListener() {
@Override
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
return getEventsForMonth(newYear,newMonth);
//return events; (if I use this the events appear 3 time)
}
};
我知道&#34; onMonthChange&#34;被称为3次,我尝试在使用它之前清除tempList,但它仍然是同样的问题 我找到了这个solution,但它不起作用
注意:方法&#34; getEventsForMonth&#34;它一直工作到昨天,我没有改变任何东西
答案 0 :(得分:0)
我在onMonthChange中使用newMonth-1解决了这个问题 因为在从日历中显示月份的值后,我发现例如1月份的每个月的值为0和+1 但onChangeMonth中的newMonth给出月份的实际值,例如1月= 1
这是新的onChangeMonth
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
int month = newMonth-1;
return getEventsForMonth(newYear,month);// I tried to use newMonth-1 directly here but it dosen't work i don't know why but it doesn't matter
}
答案 1 :(得分:0)
问题在于此函数运行3次,因此您需要执行一个匹配的日期,该日期仅返回该特定月份的事件。