即使我将最小日期应用于今天的当前日期。
我仍然可以选择过去的日期。
这是我的代码:
ViewUtilities.createDateDialog(context,
new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
View view = dialog.getCustomView();
DatePicker datePicker = (DatePicker) view.findViewById(R.id.datePicker);
datePicker.setMinDate(System.currentTimeMillis() - 1000);
int day = datePicker.getDayOfMonth();
int month = datePicker.getMonth() + 1;
int year = datePicker.getYear();
String monthString = month < 10 ? "0" + month : Integer.toString(month);// here I added 1 to the month
String dayString = day < 10 ? "0" + day : Integer.toString(day);// here I added 1 to the month
String date = year + "-" + monthString + "-" + dayString;
if (listener != null) {
listener.onUpdateDateRemarks(checkListQuestionId, date);
}
}
}, new MaterialDialog.SingleButtonCallback() {
@Override
public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
dialog.dismiss();
}
});
我的创建DateDialog:
public static void createDateDialog(Context context,
MaterialDialog.SingleButtonCallback positiveCallback,
MaterialDialog.SingleButtonCallback negativeCallback) {
new MaterialDialog.Builder(context)
.title("Select Target Date")
.positiveText("OK")
.negativeText("CANCEL")
.customView(R.layout.dialog_date, false)
.positiveColorRes(R.color.colorRed)
.negativeColorRes(R.color.colorRed)
.canceledOnTouchOutside(false)
.onPositive(positiveCallback)
.onNegative(negativeCallback)
.canceledOnTouchOutside(false)
.show();
}
即使有,我仍然可以选择过去的日期
datePicker.setMinDate(System.currentTimeMillis()-1000);
有什么我想念的吗?我能做些什么吗?