Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable dates only between current date and previous 7 days on DatePickerDialog? [duplicate]

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?

like image 307
Zin Win Htet Avatar asked Feb 08 '23 13:02

Zin Win Htet


1 Answers

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());
like image 113
Shoeb Siddique Avatar answered Feb 15 '23 10:02

Shoeb Siddique