检查的值
startWithDate.get(Calendar.DAY_OF_MONTH)
是的。它可能对应用于日期选择器的情况无效,例如max range。
为了正确处理它,您可以在输入超出范围时显示最小日期或最大日期。
if (startWithDate != null
&& (startWithDate.getTimeInMillis() < picker.getMaxDate())
&& (startWithDate.getTimeInMillis() > picker.getMinDate())) {
picker.updateDate(
startWithDate.get(Calendar.YEAR),
startWithDate.get(Calendar.MONTH),
startWithDate.get(Calendar.DAY_OF_MONTH));
} else {
// In case of invalid date set it to minimum
startWithDate.setTimeInMillis(picker.getMinDate());
// Or if you want to set it to maximum
// startWithDate.setTimeInMillis(picker.getMaxDate());
picker.updateDate(
startWithDate.get(Calendar.YEAR),
startWithDate.get(Calendar.MONTH),
startWithDate.get(Calendar.DAY_OF_MONTH));
}