I am trying to create a DatePicker in android for selecting Date of birth of a user. i want to set the year in a way that the age selected from the datepicker is greater than 18 years. For eg. if someone clicks on datetimepicker dialog, he/she should see max year as 1998 as its is equivalent to 18 years.
My code goes like:
dobDatePicker = new DatePickerDialog(getContext(), AlertDialog.THEME_HOLO_LIGHT, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
candidateDob.setText(dateFormatter.format(newDate.getTime()));
}
},newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
dobDatePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
so for now, the restriction is till the current date. Please help :)