2

I have setMaxDate in datepickerdialog. Its working well, but the minimum value in year segment is 1980. How can i set that value to, say 1900. my code is :

DatePickerDialog dp=new DatePickerDialog(getParent(),datesetListener,day,month,year);
dp.getDatePicker().setMaxDate(System.currentTimeinMillis());
Lucifer
  • 29,392
  • 25
  • 90
  • 143

2 Answers2

1

Try this dp.setMinDate(new Date(1900,1,1));

Aakash
  • 1,860
  • 19
  • 30
1

You can get the underlying DatePicker from a DatePickerDialog (by simply calling getDatePicker()) and set its bounds using:

setMinDate(long minDate)

setMaxDate(long maxDate)

Where the argument is the usual number of milliseconds since January 1, 1970 00:00:00 in the default time zone. You'll still have to calculate these values of course, but that should be trivial to do with the Calendar class: just pass current date and add or substract x years from that.

Referenced from here and here

Sample code

        Date min = new Date(2013-1900, 4, 21);
        DatePicker p = getDatePicker();
        p.setMinDate(min.getTime());
Community
  • 1
  • 1
Jitender Dev
  • 6,907
  • 2
  • 24
  • 35