how to populate a gridview for a calendar?
i have a 7x6 grid.here i have to populate the calendar for the selected month. i have dat开发者_StackOverflow社区e,month and year.with the help of these value is it possible to populate my grid view with the help of any algorithm? same like this
I would say utilize the java "GregorianCalendar" class:
http://developer.android.com/reference/java/util/GregorianCalendar.html
I wrote a simple java program to demonstrate how you would populate it:
//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();
}
精彩评论