Disable future dates in Android date picker

Hi everyone: How to disable future dates in DatePickerDialog on Android.

I am using the following implementation. http://www.androidpeople.com/android-datepicker-dialog-example

Thanks Ashwani

+7
source share
1 answer

You should be able to call getDatePicker (). setMaxDate (long) in your DatePickerDialog to set today as the maximum date. You can update a function with the same name from a published snippet.

Please note that DatePickerDialog is the object that I referenced in Android Docs from the link I posted.

@Override protected Dialog onCreateDialog(int id) { Calendar c = Calendar.getInstance(); int cyear = c.get(Calendar.YEAR); int cmonth = c.get(Calendar.MONTH); int cday = c.get(Calendar.DAY_OF_MONTH); switch (id) { case DATE_DIALOG_ID: //start changes... DatePickerDialog dialog = new DatePickerDialog(this, mDateSetListener, cyear, cmonth, cday); dialog.getDatePicker().setMaxDate(new Date().getTime()); return dialog; //end changes... } return null; } 
+19
source

All Articles