Android DatePicker 日期限制

标签 android datepicker android-date

我在 Activity 中使用 DatePicker,

我想将用户选择的日期限制为今天的日期。

他们不应该选择比今天晚的日期。

谢谢。

最佳答案

是的,你可以很容易地做到这里的验证是一个例子:

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();
            }

归功于: http://www.brighthub.com/mobile/google-android/articles/41545.aspx

关于Android DatePicker 日期限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4943486/

相关文章:

android - 如何在编辑文本中设置日期

javascript - react-native app 已经启动,现在添加导航

java - 构建 apk 文件时出错

java - BufferSize 在 android AudioRecord 中减少

JavaFX - DatePicker 始终返回 null

javascript - jQuery UI Datepicker - 禁用当前日期但不突出显示

android - Android 应用程序的安全性

java.text.ParseException : Unparseable date: "2014-06-04" (at offset 5) 异常

java - 如何在android中获取两个日期之间的周间隔?

android - 以编程方式将多个 TextView 添加到 LinearLayout