Igal
Igal

Reputation: 6083

Setting android datepicker min date to specific date

I want the user to be able to pick start date and end date. The minimum of end date must be equal to start date. For example the user selects August 1 2014 as a start date. When he clicks on the return date field these values are passed to date_picker_activity as intent extras. In the date_picker_activity I check for these extras and currently it just sets the selected date as the displayed date:

if(getIntent().getExtras()!=null)
{
    int year = getIntent().getExtras().getInt("SELECTED_YEAR");
    int month = getIntent().getExtras().getInt("SELECTED_MONTH");
    int day = getIntent().getExtras().getInt("SELECTED_DAY");
    date_picker.updateDate(year, month, day);
}

but the user is still able to pick dates prior to selected start date.

I tried to do something like that inside that if statement:

Time time = new Time();
time.set(day, month, year);
date_picker.setMinDate(time.toMillis(true)-1000);

but that didn't work.

How can I set the min date with the passed values?

Upvotes: 2

Views: 1796

Answers (1)

joao2fast4u
joao2fast4u

Reputation: 6892

After discussing on chat, we managed to understand that this code:

date_picker.setMinDate(System.currentTimeMillis() - 1000);

was being called anyway inside the if statement, setting the minimum date to the current Date.

Once Igal moved that code to an else statement, all is working ok.

Upvotes: 2

Related Questions