我正在尝试创建一个自定义日历视图,为此我使用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
更多推荐
发布评论