使用最小/最大限制时,Android DatePicker显示不可用的月份 [英] Android DatePicker shows unavailable months when using min/max limits

查看:174
本文介绍了使用最小/最大限制时,Android DatePicker显示不可用的月份的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在StackOverflow上仅发现了该问题的其他1个实例(去年未得到答复),所以我想再给它一个镜头. ( Android DatePicker/对话框显示不正确的月份/秒使用最小/最大日期,并带有实际图像)

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)

设置Android DatePicker的minDate和maxDate时,它将显示在最小和最大日期范围内不可用的月份. 我将通过以下图像演示此问题:

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:

当我在minDate时:

When I'm at the minDate:

当我在日期限制之间时:

When I'm in between the date limits:

当我处于maxDate时:

When I'm at the maxDate:

在这种情况下,不可用的月份(在这种情况下为4月和6月)充当最小值和最大值,因此到4月,DatePicker将拍摄到5月15日,或者尝试滑动到6月会将DatePicker移到5月22日.

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.

是否可以将那些(不可用的)月份隐藏起来,所以在此测试用例中,唯一可选择的部分是日期?另外请记住,例如在5月29日到6月5日之间有一个间隔,则6月必须出现在列表中.

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.

推荐答案

我通过将当前时间重置为午夜来解决了该问题:

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());

这篇关于使用最小/最大限制时,Android DatePicker显示不可用的月份的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆