/** * 创建一个7x7的日期网格 */ private void createCalenderGrid() { //创建一个7×7的网格 for (int i = 0; i < 49; i++) { CalndarGridItem item = new CalndarGridItem(); // 第一行为星期页签 if (i < 7) { item.setWeekDay(g_weeklabels[i]); item.setTextColor(Color.FromArgb(50, 63, 86)); } else { // 注册点击事件 item.setOnGridItemClickListener(new CalndarGridItemClickHandler(onGridItemClickListener)); } gridView.Controls.Add(item); mCalenderItemList.Add(item); } }
private void createGrid(int addMonth) { if (File.Exists(eventFileName)) { SaveXML <Dictionary <int, List <Event> > > saver = new SaveXML <Dictionary <int, List <Event> > >(); mEvents = saver.GetData(mEvents, eventFileName); } gridView.Controls.Clear(); String[] months = { "su", "mo", "tu", "we", "th", "fr", "sa" }; for (int i = 0; i < 7; i++) { CalndarGridItem item = new CalndarGridItem(); item.setText(months[i]); item.setTextColor(Color.FromArgb(50, 63, 86)); gridView.Controls.Add(item); } DateTime temp; DateTime today = DateTime.Today; if (addMonth != 0) { today = today.AddMonths(addMonth); } DateTime nextMonth = today.AddMonths(1); DateTime prevMonth = today.AddMonths(-1); temp = new DateTime(today.Year, today.Month, 1); int dayOfWeek = (int)temp.DayOfWeek; int dayOfPrevMonth = System.DateTime.DaysInMonth(prevMonth.Year, prevMonth.Month); for (int i = dayOfWeek - 1; i >= 0; i--) { CalndarGridItem item = new CalndarGridItem(); item.setText((dayOfPrevMonth - i) + ""); item.setTextColor(Color.FromArgb(50, 63, 86)); gridView.Controls.Add(item); } int daysOfCurrentMonth = System.DateTime.DaysInMonth(today.Year, today.Month); for (int i = 1; i <= daysOfCurrentMonth; i++) { CalndarGridItem item = new CalndarGridItem(); item.setText(i + ""); if (addMonth == 0 && i == (int)DateTime.Today.Day) { item.makeToDay(); } item.setDateTime(today); item.getTextView().Cursor = Cursors.Hand; item.setOnGridItemClickListener(new EventHandler(onGridItemClickListener)); String key = i + " " + today.ToString("MMMM").Substring(0, 3) + " " + today.Year; if (mEvents.ContainsKey(key.GetHashCode())) { if (addMonth <= 0 && i < TODAY.Day) { item.hadNote(); } else { item.hasNote(); } } gridView.Controls.Add(item); } int daysOfNextMonth = dayOfWeek - 1 + daysOfCurrentMonth; for (int i = 1; i < 35 - daysOfNextMonth; i++) { CalndarGridItem item = new CalndarGridItem(); item.setText(i + ""); item.setTextColor(Color.FromArgb(50, 63, 86)); gridView.Controls.Add(item); } currentMonth.Text = today.ToString("MMMM"); currentYear.Text = today.Year + ""; }