为什么此CalendarView为空(什么也不显示)? [英] Why is this CalendarView empty (showing nothing)?
问题描述
我正在开发一个名为Infinite Calendar的应用程序.它不是无限的,因为一切都有极限,我现在正在寻找这个极限.我正在使用CalendarView
来显示日历,并使用JodaTime来帮助我处理日期.
I am developing an app called Infinite Calendar. And it is not infinite because everything has a limit and I am now finding this limit. I am using a CalendarView
to display a calendar and JodaTime to help me to deal with dates.
我的布局只有一个视图:
My layout has only one view:
<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:showWeekNumber="false"
android:shownWeekCount="5"
android:id="@+id/calendar">
</CalendarView>
我正在通过代码设置maxDate
和minDate
:
And I am setting the maxDate
and minDate
by code:
calendar.setMinDate (0);
calendar.setMaxDate (9223372017014400000L);
为什么我要使用9223372017014400000L
?因为经过一些实验,我发现这是JodaTime可以获得的最大值.为什么不将它们设置在布局文件中?因为我不知道格式.我之前尝试过几次,但是它一直抛出异常,说最大小于最小...
And why did I use 9223372017014400000L
? Because after some experiments, I found that is the maximum that JodaTime can get. And why didn't I set them in the layout file? Because I don't know the format. I tried a few times before but it kept throwing exceptions saying that the max is less than the min...
现在,我认为,到目前为止,一切都很好.因此,我尝试将日期设置为一些非常大的数字:
Now I think, that's so far so good. So I tried to set the date to some really big numbers:
Date date = new LocalDate (2000000, 1, 1).toDate ();
calendar.setDate (date.getTime ());
实际上,我什至不知道我是否做得很好,或者只是在屠宰它.
Actually I don't even know if I am doing this well or if I am just butchering this.
现在奇怪的事情发生了.当我运行该应用程序时,CalendarView
只会在顶部显示月份,年份和星期几!我搜索并发现了另一个与此类似的问题:
Now the strange thing happens. When I run the app, the CalendarView
shows nothing but the month, the year and the days of week at the top! I searched and found another question similar to this:
但是答案告诉OP将尺寸设置为match_parent
,这显然是我做的.
But the answer told the OP to set the dimensions to match_parent
, which I did apparently.
那么问题来了,这是否有特殊原因?如果是,那是什么,我该如何解决?如果否,CalendarView
的限制是多少?
So here comes the questions, is there a special cause of this? If yes, what is it and how can I fix it? If no, what is the limit of CalendarView
?
更新:
我尝试将最小日期设置为默认值(未指定),将最大日期设置为1/1/2000000,然后将日期设置为1/12000000.现在,日历视图将显示日期和其他日期(1999999)!真奇怪!
I tried to set the min date to default (not specifying that) and the max date to 1/1/2000000 and then set the date to 1/12000000. Now the calendar view shows the the date and other dates in 1999999! How weird!
乔恩·斯基特(Jon Skeet),请帮助我!
Jon Skeet please help me!
推荐答案
从我自己的手机上使用Google自己的日历应用程序(直到2038年)来看,我想他们的CalendarView
会遇到由 2038年问题.这可能是它支持的最长日期,尽管我在文档中找不到任何提及.
Judging by Google's own Calendar app on my phone which only goes up to the year 2038, I imagine their CalendarView
suffers from a similar issue created by the Year 2038 Problem. This is probably the maximum date it supports, though I couldn't find any mention of that in the documentation.
您最好使用时间的64位表示形式来研究其他解决方案或编写自己的解决方案-这应该可以覆盖大约3,000亿年...
You're probably better off looking into other solutions or writing your own, using 64 bit representations of the time - this should cover you for approximately 300 billion years...
顺便说一句:JodaTime使用时间的64位表示,因此要获得最大值,您要做的所有工作就是将63个连续的1s转换为十进制,从而得到9223372036854775807
.无需进行实验,并且略高于您的结果.
An aside: JodaTime uses a 64 bit representation of the time, so all you have to do to get the max is convert 63 consecutive 1s to decimal which gets you 9223372036854775807
. No experiments required and slightly higher than your result.
这篇关于为什么此CalendarView为空(什么也不显示)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!