我有一个7x6网格。我必须填写所选月份的日历。 我有日期,月份和年份。借助这些值,可以在任何算法的帮助下填充我的网格视图吗?与此
相同答案 0 :(得分:9)
我想说使用java“GregorianCalendar”类:
http://developer.android.com/reference/java/util/GregorianCalendar.html
我写了一个简单的java程序来演示如何填充它:
//calendar for November 1986
GregorianCalendar gCal = new GregorianCalendar(1986, Calendar.NOVEMBER, 1);
//this gets the day of week range 1-7, Sunday - Saturday
int currentDay = gCal.get(Calendar.DAY_OF_WEEK);
//backtracks to the beginning of current week (Sunday)
gCal.add(Calendar.DAY_OF_YEAR, Calendar.SUNDAY - currentDay);
int gridSizeX = 7, gridSizeY = 6;
for (int i = 0; i < gridSizeY; i++)
{
for (int j = 0; j < gridSizeX; j++)
{
//fill in your cell with this value
System.out.print(gCal.get(Calendar.DAY_OF_MONTH));
System.out.print(" ");
//add one to the day and keep going
gCal.add(Calendar.DAY_OF_YEAR, 1);
}
System.out.println();
}