16

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.

Community
  • 1
  • 1
Kevin
  • 183
  • 8
  • I haven't looked through the code, but I can guess that it is most likely due to as you describe--in the case where part of the month needs to be available it needs to show the month in the list. I'm guessing the min/max code is liberal in showing the previous/next month in the list in the scroller to simplify the logic quite a bit. I figure, as long as it doesn't let the user actually select/confirm a date outside the range at the end of the UI processes, I think you'll be fine. What is your concern with it showing too much in the scroller in some cases? Is it confusing your users? – Jon Adams May 18 '15 at 22:55
  • Basically that. The user can't select any 'invalid' dates, but it was an immediate concern at our testers (and well, it looked weird to me as well). The concern of the testers is mainly from an UX point of view, which is understandable to me. So if there was a way to resolve this, it would've been nice. But from the looks of it, this is simply functionality that is built into Android and doesn't seem to be adjustable, sadly. – Kevin May 20 '15 at 08:39
  • I had the same problem with testers, I told them that it was the way this native widget works and I have no power over it, told them to submit a bug at google if they wanted – Kaloyan Roussev Jun 20 '15 at 22:59
  • I've experienced other off behavior with the DatePicker, but often it occurs on only specific devices. I suggest trying on a few different devices, and using the calendar view as well as the picker view--perhaps the calendar view works better, or the problem only occurs on one device. Or maybe it's just buggy. – Chad Schultz Jul 29 '15 at 19:13

2 Answers2

2

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());
funcoder
  • 1,975
  • 20
  • 14
0

OPTION 1. You could use android-times-square

and give in a custom date range so that it fades out the unavailable dates, gives more visual representation too

Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);

CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Date today = new Date();
calendar.init(today, nextYear.getTime())
    .inMode(RANGE);
Rejo Chandran
  • 599
  • 4
  • 22