禁用Android的日期选择将来的日期 [英] Disable future dates in Android date picker

查看:110
本文介绍了禁用Android的日期选择将来的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好所有: 如何禁用DatePickerDialog将来的日期在Android中。

Hello All: How to disable future dates in DatePickerDialog in Android.

我使用下面的实现。 <一href="http://www.androidpeople.com/android-datepicker-dialog-example">http://www.androidpeople.com/android-datepicker-dialog-example

谢谢 Ashwani

Thanks Ashwani

推荐答案

您应该能够调用getDatePicker()。<一个href="http://developer.android.com/reference/android/widget/DatePicker.html#setMaxDate%28long%29">setMaxDate(long)您DatePickerDialog今天设置你的最大日期。您可以更新从您发布的代码片段中的相同名称的功能。

You should be able to call getDatePicker().setMaxDate(long) on your DatePickerDialog to set today as your max date. You can update the function with the same name from the snippet you posted.

请注意的DatePickerDialog是我在Android文档中引用从我张贴的链接的对象。

Note the DatePickerDialog is the object that I referenced in the Android Docs from the link I posted.

@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的日期选择将来的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆