在Android日期选择器中停用未来日期

大家好:
如何在 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;
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...