4

Following pic is a web date picker. There, only between current date and previous 7 days are able to be selected.

enter image description here

I've to do this at Android using DatePickerDialog. I implemented DatePickerDialog on my EditText's OnClickListener as an example here. The question is how to make user could not select out of that range? Any idea?

Zin Win Htet
  • 2,448
  • 4
  • 32
  • 54

1 Answers1

8

You can set minimum and maximum date.

Calendar cal = Calendar.getInstance();

cal.add(Calendar.DAY_OF_MONTH, -7);
Date result = cal.getTime();
mDatePicker.setMaxDate(System.currentTimeMillis());
mDatePicker.setMinDate(result.getTime());
Shoeb Siddique
  • 2,805
  • 1
  • 22
  • 42