Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Display dates correctly in grid
- */
- public void updateCalendar(HashSet<Date> events)
- {
- ArrayList<Date> cells = new ArrayList<>();
- Calendar calendar = (Calendar)currentDate.clone();
- // determine the cell for current month's beginning
- calendar.set(Calendar.DAY_OF_MONTH, 1);
- int monthBeginningCell = calendar.get(Calendar.DAY_OF_WEEK) - 2;
- // move calendar backwards to the beginning of the week
- calendar.add(Calendar.DAY_OF_MONTH, -monthBeginningCell);
- // fill cells
- while (cells.size() < DAYS_COUNT)
- {
- cells.add(calendar.getTime());
- calendar.add(Calendar.DAY_OF_MONTH, 1);
- }
- // update grid
- gridView.setAdapter(new CalendarAdapter(getContext(), cells, events));
- // update title
- SimpleDateFormat sdf = new SimpleDateFormat("EEEE,d MMM,yyyy");
- String[] dateToday = sdf.format(currentDate.getTime()).split(",");
- txtDateDay.setText(dateToday[0]);
- txtDisplayDate.setText(dateToday[1]);
- txtDateYear.setText(dateToday[2]);
- }
Add Comment
Please, Sign In to add comment