我正在开展一个项目,我需要限制用户选择任何其他日期而不是我想要的日期。
通过阅读一些文章和SO帖子我尝试了以下应该工作
com.wdullaer.materialdatetimepicker.date.DatePickerDialog dpd = newInstance(
ActivityClaimOffers.this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
dpd.setMinDate(calendar);
dpd.setMaxDate(calendar);
但我 无法弄清楚如何将自定义日期作为日历对象传递。 因为setMinDate()和setMaxDate()都将Calendar作为参数
答案 0 :(得分:3)
像这样:
@try{
[self removeObserver:self forKeyPath:@"location"];
}@catch(id anException){
//catch the exception
}
代码:
Calendar calendar = new GregorianCalendar(year, monthOfYear, dayOfMonth);
答案 1 :(得分:3)
嘿,尝试像我这样做的代码
Calendar nowMinimum = Calendar.getInstance();
DatePickerDialog dpd = DatePickerDialog.newInstance(
this,
nowMinimum.get(Calendar.YEAR),
nowMinimum.get(Calendar.MONTH),
nowMinimum.get(Calendar.DAY_OF_MONTH));
dpd.setMinDate(nowMinimum); //today's date is minimum
Calendar thenMaximum = Calendar.getInstance();
thenMaximum.set(year, monthOfYear, dayOfMonth);// you can pass your custom date
dpd.setMinDate(thenMaximum);
dpd.setTitle("Select Date");
dpd.show(getActivity().getFragmentManager(), "date_picker");