仍然能够选择日期选择器中的禁用日期 [英] Still able to select disabled dates in date picker

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

问题描述

我想在Android中禁用日期选择器的过去日期。
我可以使用

I want to disable the past dates of date picker in android. i can do it by using

dialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);

这是正常的,日期选择器中的过去日期看起来被禁用。但是我仍然可以点击上一个日期并选择它。
怎么不让这种情况发生?以下
是我的日期选择器的截图: -

This is working fine and the past dates in date picker looks disabled. But I can still click on a previous date and select it. How to not let that happen ? below is the screenshot of my date picker :-

这里是我的代码,我禁用过去的日期: -

And here is my code where I am disabling the past dates :-

@Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // Use the current date as the default date in the picker
        final Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);
        mActivity = new WeakReference<CreateEvent>(
                (CreateEvent) getActivity());

        DatePickerDialog dialog = new DatePickerDialog(getActivity(), this, year, month, day);

        if(callingView==fromDate){
            dialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
        }else if (callingView==toDate){
            dialog.getDatePicker().setMinDate(fromD);
        }

        // Create a new instance of DatePickerDialog and return it
        return dialog;
    }


推荐答案

这是棒棒糖的错误。

所有您需要做的是检查选定的日期,并设置最小日期。

All you need to do is check the selected date with the min date set.

这篇关于仍然能够选择日期选择器中的禁用日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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