我想在日历中仅显示当前周值。我正在使用此示例代码:
Custom Calendar in Android | Android Calendar Example with full source code
并编辑几行以获得显示当前周日期的单行。
结果如下:
...但我的代码仅显示截至今天的日期,并且未显示明天或后天的日期。我该怎么办?
我想要这样的事情:
Sun Mon Tues Wednes Thurs Fri sat
21 22 23 24 25 26 27
但我的代码显示:
Sun Mon Tues Wednes Thurs Fri sat
21 22 1 2 3 4 5
我从示例代码中更改了此代码:
// Current Month Days
for (int i = 1; i <= daysInMonth; i++) {
Log.d(currentMonthName, String.valueOf(i) + " "
+ getMonthAsString(currentMonth) + " " + yy);
if (i == getCurrentDayOfMonth()) {
list.add(String.valueOf(i) + "-BLUE" + "-"
+ getMonthAsString(currentMonth) + "-" + yy);
} else {
list.add(String.valueOf(i) + "-WHITE" + "-"
+ getMonthAsString(currentMonth) + "-" + yy);
}
}
使用此代码:
// Current Month Days
int startDate = 0;
for (int i = 1; i <= daysInMonth; i++) {
Log.d(currentMonthName, String.valueOf(i) + " "
+ getMonthAsString(currentMonth) + " " + yy);
startDate=getCurrentDayOfMonth()-(list.size() % 7);
System.out.println("**********"+startDate);
if (i == getCurrentDayOfMonth()) {
list.add(String.valueOf(i) + "-BLUE" + "-"
+ getMonthAsString(currentMonth) + "-" + yy);
break;
} else {
list.add(String.valueOf(i) + "-WHITE" + "-"
+ getMonthAsString(currentMonth) + "-" + yy);
}
}
//removing itmem fro list
System.out.println("----------------------"+startDate);
System.out.println(list.size());
for(int k=1;k<=startDate;k++){
System.out.println("Item remove"+k);
list.remove(0);
}
答案 0 :(得分:1)
if (i == getCurrentDayOfMonth()) {
list.add(String.valueOf(i) + "-BLUE" + "-"
+ getMonthAsString(currentMonth) + "-" + yy);
break;
}
在那里,删除休息。一旦你点击“今天”,你就会摆脱for循环。