Android DatePicker Date Limiting

后端 未结 4 1871
执笔经年
执笔经年 2020-12-16 04:00

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.

4条回答
  •  难免孤独
    2020-12-16 04:33

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

    Credits to: http://www.brighthub.com/mobile/google-android/articles/41545.aspx

提交回复
热议问题