背景:我正在开发一个 Android 项目,在该项目中会引发日期预订的并发,并且我使用MaterialDatePicker来选择日期。
问题:我需要禁用一些其他用户已经选择的特定日期以处理并发。我能够从 Firestore(Firebase - 后端开发平台)中获取其他用户选择的日期,但无法处理日历。我遇到了一个建议使用setDisabledDays(calender[] days)的博客,但不太清楚该怎么做?!
需要帮助!- 我如何禁用日历上的特定日期???
Calendar calendar = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
calendar.clear();
long today = MaterialDatePicker.todayInUtcMilliseconds();
calendar.setTimeInMillis(today);
calendar.set(Calendar.MONTH, Calendar.JANUARY);
long January = calendar.getTimeInMillis();
calendar.set(Calendar.MONTH, Calendar.DECEMBER);
long December = calendar.getTimeInMillis();
CalendarConstraints.Builder calenderConstraintBuilder = new CalendarConstraints.Builder();
calenderConstraintBuilder.setOpenAt(today);
calenderConstraintBuilder.setValidator(DateValidatorPointForward.now());
MaterialDatePicker.Builder builder = MaterialDatePicker.Builder.datePicker();
builder.setTitleText("Select start date");
builder.setCalendarConstraints(calenderConstraintBuilder.build());
MaterialDatePicker materialDatePicker = builder.build();
mDatePickerBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
materialDatePicker.show(getSupportFragmentManager(), "DATE_PICKER");
}
});
materialDatePicker.addOnPositiveButtonClickListener(new MaterialPickerOnPositiveButtonClickListener() {
@Override
public void onPositiveButtonClick(Object selection) {
duration = materialDatePicker.getHeaderText();
//This duration variable must be stored in database, it has both start and end date
dateResult.setText("Selected dates: " + duration);
}
});