我需要确保用户不会选择未来日期作为筛选记录的选择。我可以限制月份,但不能限制未来的日期。请帮忙。
这是我使用的代码:
// create the instance of the calendar to set the
// bounds
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
// now set the starting bound from current month to
// previous MARCH
/*calendar.set(Calendar.MONTH, Calendar.MARCH);
long march = calendar.getTimeInMillis();*/
// now set the ending bound from current month to
// DECEMBER
//calendar.set(Calendar.MONTH, Calendar.DECEMBER);
//long december = calendar.getTimeInMillis();
calendar.set(Calendar.DATE, Calendar.DAY_OF_MONTH);
long currentDateTimeMills = calendar.getTimeInMillis();
// create the instance of the CalendarConstraints
// Builder
CalendarConstraints.Builder calendarConstraintBuilder = new CalendarConstraints.Builder();
// and set the start and end constraints (bounds)
//calendarConstraintBuilder.setStart(march);
//calendarConstraintBuilder.setEnd(december);
calendarConstraintBuilder.setEnd(currentDateTimeMills);
MaterialDatePicker.Builder<Pair<Long, Long>> materialDateBuilder = MaterialDatePicker.Builder.dateRangePicker();
materialDateBuilder.setTitleText("SELECT A DATE");
materialDateBuilder.setCalendarConstraints(calendarConstraintBuilder.build());
//final MaterialDatePicker<Pair<Long, Long>> materialDatePicker = materialDateBuilder.build();
final MaterialDatePicker materialDatePicker = materialDateBuilder.build();
dateRangePickerButton.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
if(fragmentManager.findFragmentByTag("MATERIAL_DATE_PICKER") == null) {
materialDatePicker.show(((FragmentActivity) v.getContext()).getSupportFragmentManager(), "MATERIAL_DATE_PICKER");
}
}
});