我正在写一个日历视图。当我按下下个月按钮时,我调用 mCalendarContainerLL.invalidate();但是我的自定义视图没有被重绘。我的自定义视图中的 onDraw 方法没有被调用。
Ps:如果我直接使所有日历单元格视图无效。它可以工作。为什么会这样???
这是代码:
private CalendarWidgetDayCell updateCalendarView() {
CalendarWidgetDayCell dayCellSelected = null;
boolean isSelected = false;
final boolean isHasSelection = (mCalendarSelected.getTimeInMillis() != 0);
final int selectedYear = mCalendarSelected.get(Calendar.YEAR);
final int selectedMonth = mCalendarSelected.get(Calendar.MONTH);
final int selectedDay = mCalendarSelected.get(Calendar.DAY_OF_MONTH);
Calendar dateXOfCalendar = Calendar.getInstance();
dateXOfCalendar.setTimeInMillis(mStartDateCurrentMonth.getTimeInMillis());
Log.d(tag, "updateCalendarView cpt_func_ " + "mDayCellList.size(): " + mDayCellList.size());
for (int i = 0; i < mDayCellList.size(); i++) {
final int yearOfCellItem = dateXOfCalendar.get(Calendar.YEAR);
final int monthOfCellItem = dateXOfCalendar.get(Calendar.MONTH);
final int dayOfCellItem = dateXOfCalendar.get(Calendar.DAY_OF_MONTH);
final int dayOfWeekOfCellItem = dateXOfCalendar.get(Calendar.DAY_OF_WEEK);
CalendarWidgetDayCell dayCellItem = mDayCellList.get(i);
boolean isToday = false;
if (mCalendarToday.get(Calendar.YEAR) == yearOfCellItem) {
if (mCalendarToday.get(Calendar.MONTH) == monthOfCellItem) {
if (mCalendarToday.get(Calendar.DAY_OF_MONTH) == dayOfCellItem) {
isToday = true;
}
}
}
// check holiday
boolean isHoliday = false;
if ((dayOfWeekOfCellItem == Calendar.SATURDAY) || (dayOfWeekOfCellItem == Calendar.SUNDAY))
isHoliday = true;
if ((monthOfCellItem == Calendar.JANUARY) && (dayOfCellItem == 1))
isHoliday = true;
isSelected = false;
if (isHasSelection) {
if ((selectedDay == dayOfCellItem) && (selectedMonth == monthOfCellItem)
&& (selectedYear == yearOfCellItem)) {
isSelected = true;
}
}
dayCellItem.setSelected(isSelected);
boolean hasRecord = false;
if (isSelected)
dayCellSelected = dayCellItem;
dayCellItem.setViewParam(yearOfCellItem, monthOfCellItem, dayOfCellItem, isToday, isHoliday,
mCurrentMonthInCalendar, hasRecord);
dayCellItem.invalidate();//It works well.
dateXOfCalendar.add(Calendar.DAY_OF_MONTH, 1);
}
// mCalendarContainerLL.invalidate();//This is not working as expected.
return dayCellSelected;
}