安卓的DatePicker日期限制 [英] Android DatePicker Date Limiting

查看:227
本文介绍了安卓的DatePicker日期限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用DatePicket在我的活动,

I am using DatePicket in my activity ,

我要限制用户挑今天的日期。

I want to limit the date picked by user to todays date.

他们不应该能够选择日期大于今天的日期。

They should not able to select date greater than todays date.

感谢你。

推荐答案

是的,你可以做到这一点很easely这里的验证是为例:

yes you can do it very easely the validation here is the exemple:

if(dateObj1.before(dateObj2) || dateObj1.equals(dateObj2)){
//the program runs normally
}
else{
                new AlertDialog.Builder(PM_Edit.this)

                .setTitle("Wrong Data Input!")

                .setMessage("The end Date must be Before the start Date, please insert new Date values")

                .setNeutralButton("Ok",

                new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog,

                int which) {

                }

                }).show();
            }

贷: <一href="http://www.brighthub.com/mobile/google-android/articles/41545.aspx">http://www.brighthub.com/mobile/google-android/articles/41545.aspx

这篇关于安卓的DatePicker日期限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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