I hope you have received an answer so far. The following may be useful for others: If you want to disconnect a user to select a date 18 years after today, here is what you can do.
Get time from 1-JAN-1970 to 18 years (in milliseconds)
Calendar cal = Calendar.getInstance(); cal.set(cal.get(Calendar.YEAR)+18,cal.get(Calendar.MONTH),cal.get(Calendar.DAY_OF_MONTH), cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), 0); long time = cal.getTimeInMillis();
set it as the maximum allowed date in datepicker
datepicker2.setMaxDate(time);
Hope this helps anyone looking for an answer.
source share