我在 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/