大家好:
如何在 Android中禁用DatePickerDialog中的未来日期.
如何在 Android中禁用DatePickerDialog中的未来日期.
我正在使用以下实现.
http://www.androidpeople.com/android-datepicker-dialog-example
谢谢
Ashwani
解决方法
您应该可以在DatePickerDialog上调用getDatePicker().
setMaxDate(long),将今天设置为最大日期.您可以使用您发布的代码段中的相同名称更新该功能.
请注意,DatePickerDialog是我在Android文档中从我发布的链接中引用的对象.
@Override
protected Dialog onCreateDialog(int id) {
Calendar c = Calendar.getInstance();
int cyear = c.get(Calendar.YEAR);
int cmonth = c.get(Calendar.MONTH);
int cday = c.get(Calendar.DAY_OF_MONTH);
switch (id) {
case DATE_DIALOG_ID:
//start changes...
DatePickerDialog dialog = new DatePickerDialog(this,mDateSetListener,cyear,cmonth,cday);
dialog.getDatePicker().setMaxDate(new Date().getTime());
return dialog;
//end changes...
}
return null;
}