Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android DatePicker shows unavailable months when using min/max limits

I've only found 1 other instance of this issue on StackOverflow which was unanswered (last year), so I figured I'd give it another shot. (Android DatePicker/Dialog displaying incorrect month/s using min/max date, with an actual image)

When setting the minDate and maxDate of the Android DatePicker, it'll show months that are unavailable within the range of min and max date. I'll demonstrate this issue with the following images:

When I'm at the minDate:

When I'm at minDate

When I'm in between the date limits:

In between dates

When I'm at the maxDate:

At maxDate

The unavailable months (in this case April and June) act as min and max values in this situation, so going to April, the DatePicker will shoot to 15th of May, or trying to slide to June will move the DatePicker to the 22th of May.

Is it possible to keep those (unavailable) months hidden from view, so in this testcase, the only selectable part would be the date? Also keeping in mind that, with an interval between for instance the 29th of May and the 5th of June, June has to appear in the list.

like image 786
Kevin Avatar asked May 15 '15 11:05

Kevin


1 Answers

I fixed that issue by resetting the current time to midnight:

Calendar date = Calendar.getInstance();
// reset hour, minutes, seconds and millis
date.set(Calendar.HOUR_OF_DAY, 0);
date.set(Calendar.MINUTE, 0);
date.set(Calendar.SECOND, 0);
date.set(Calendar.MILLISECOND, 0);
datePicker.setMaxDate(date.getTimeInMillis());
like image 99
funcoder Avatar answered Oct 19 '22 05:10

funcoder