I have a DatePicker in my activity. I want to set the year max limit to 2000, so that datepicker dont show years which is exceed year 2000. how can i implement this.currently i have used this code to set current date :
dialog.getDatePicker().setMaxDate(new Date().getTime());
current work img :
I want look this :
this is my code :
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;
}
use this piece of code
protected Dialog onCreateDialog(int id) {
Date d=new Date();
Calendar cal=Calendar.getInstance();
cal.set(2000, 1, 1, 0, 0);
d.setTime(cal.getTimeInMillis());
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(d.getTime());
return dialog;
// end changes...
}
return null;
}