Android MonthDisplayHelper不按正确的顺序提供日期(Android MonthDisplayHelper doesn't provide the days in th

编程入门 行业动态 更新时间:2024-10-13 14:23:21
Android MonthDisplayHelper不按正确的顺序提供日期(Android MonthDisplayHelper doesn't provide the days in the proper order)

我正在尝试创建一个自定义日历视图,为此我使用MonthDisplayHelper来获取月份的日期,并使用GridView来显示它们。

问题是MonthDisplayHelper没有给我正确的日期订单,例如,如果当前日期是02.20.2012,则MonthDisplayHelper按此顺序给出了以下日期:

太阳---星期一---星期二---星期三---星期四---星期五---星期六

31 -------- 1 ------ 2 ------ 3 ------- 4 ------ 5 ------ 6

7 ------ 8 ------ 9 ------ 10 ------ 11 ------ 12 ---- 13

14 ----- 15 ----- 16 ----- 17 ----- 18 ----- 19 ----- 20 - <=这里的当天是星期六,但实际上是是星期一

21 ----- 22 ----- 23 ----- 24 ----- 25 ----- 26 ----- 27

28 ------ 29 ------ 1 ------ 2 ------ 3 ------ 4 ------ 5

因此,前一个月的日子应该从29日(星期日)开始,到下个月的日子结束(星期六3日)

我从MonthDisplayHelper那里得到了这样的日子:

calendarHelper = new MonthDisplayHelper(2012, 1, Calendar.SUNDAY); int thisDay = calendarHelper.getDayAt(rowIndex, columnIndex);

每次调用getView()时我都会增加rowIndex和columnIndex:

if (columnIndex >= 7) { rowIndex++; columnIndex = -1; } columnIndex += 1;

I am trying to make a custom Calendar view and for that I use MonthDisplayHelper to get the days of the month and a GridView to display them.

The problem is that MonthDisplayHelper is not giving me the right days order, for example if the current date is 02.20.2012, the MonthDisplayHelper gives me the following days in this order:

Sun --- Mon --- Tue --- Wed --- Thu --- Fri --- Sat

31 --------1 ------ 2 ------ 3------- 4 ------ 5 ------ 6

7 ------ 8 ------ 9 ------ 10 ------ 11 ------ 12 ---- 13

14 ----- 15 ----- 16 -----17 ----- 18 ----- 19 ----- 20 -- <= the current day here is Sat but in reality is Mon

21 ----- 22 ----- 23 ----- 24 ----- 25 ----- 26 ----- 27

28 ------ 29 ------1 ------ 2 ------ 3 ------ 4 ------ 5

So the previous month days should start from 29(on Sunday) and end with the next month days (3 on Sat)

I get the days from the MonthDisplayHelper like this:

calendarHelper = new MonthDisplayHelper(2012, 1, Calendar.SUNDAY); int thisDay = calendarHelper.getDayAt(rowIndex, columnIndex);

and I am incrementing the rowIndex and columnIndex each time the getView() is called like this:

if (columnIndex >= 7) { rowIndex++; columnIndex = -1; } columnIndex += 1;

最满意答案

似乎问题是gridview适配器,当它运行时它连续两三次给我相同的索引,只有在那之后索引才会增加..我修改了increment方法来增加列和行的增量仅当网格索引与上一个给定的网格索引不同时才使用索引。

我仍然想知道为什么适配器正在做这个奇怪的事情..也许有人可以告诉为什么..

谢谢

It seems that the problem was the gridview adapter, when it runs it gives me the same index for two or three time in a row and only after that the index gets incremented.. I modified the increment method to do the incrementation of column and row index only if the grid index is not the same as the last given one..

I'm still wondering why the adapter is doing this strange thing.. maybe someone could tell why..

Thanks

更多推荐

本文发布于:2023-08-07 17:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465362.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不按   顺序   正确   日期   MonthDisplayHelper

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!