I have implemented datepicker dialog in my app successfully, have doubt in disabling the dates, check it out my code
To get the year which is 13 year above the current year
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
String now = df.format(new java.util.Date());
String[] datevalues = now.split("/");
int yearsum = Integer.parseInt(datevalues[2]);
int i;
for (i = 0; i < 13; i++) {
yearsum = yearsum - 1;
Log.d("i", "i" + i + yearsum);
}
finaldate = yearsum;
My DatePicker dialog
Calendar calender = Calendar.getInstance();
int year = calender.get(Calendar.YEAR);
int month = calender.get(Calendar.MONTH);
int day = calender.get(Calendar.DAY_OF_MONTH);
Date newDate = new Date(Long.parseLong(getString(finaldate)));
DatePickerDialog dialog = new DatePickerDialog(Signup.this,
new DateListener(), year, month, day);
// To set the maximum year
dialog.getDatePicker().setMaxDate(finaldate);
dialog.show();
Now i need to show the date upto the date which is 13 years before the current date,
i have used dialog.getDatePicker().setMaxDate(finaldate);
line to filter the dates but no luck.`have tried with google but dint get the proper solution. help me to get the solution.
Thanks
To calculate a date 13 years ago from today:
Calendar then = Calendar.getInstance();
then.add(Calendar.YEAR, -13);
To apply it as the max date in date picker:
...getDatePicker().setMaxDate(then.getTimeInMillis());