Guest User

Untitled

a guest
Mar 17th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. /**
  2. * Display dates correctly in grid
  3. */
  4. public void updateCalendar(HashSet<Date> events)
  5. {
  6. ArrayList<Date> cells = new ArrayList<>();
  7. Calendar calendar = (Calendar)currentDate.clone();
  8.  
  9. // determine the cell for current month's beginning
  10. calendar.set(Calendar.DAY_OF_MONTH, 1);
  11. int monthBeginningCell = calendar.get(Calendar.DAY_OF_WEEK) - 2;
  12.  
  13. // move calendar backwards to the beginning of the week
  14. calendar.add(Calendar.DAY_OF_MONTH, -monthBeginningCell);
  15.  
  16. // fill cells
  17. while (cells.size() < DAYS_COUNT)
  18. {
  19. cells.add(calendar.getTime());
  20. calendar.add(Calendar.DAY_OF_MONTH, 1);
  21. }
  22.  
  23. // update grid
  24. gridView.setAdapter(new CalendarAdapter(getContext(), cells, events));
  25.  
  26. // update title
  27. SimpleDateFormat sdf = new SimpleDateFormat("EEEE,d MMM,yyyy");
  28. String[] dateToday = sdf.format(currentDate.getTime()).split(",");
  29. txtDateDay.setText(dateToday[0]);
  30. txtDisplayDate.setText(dateToday[1]);
  31. txtDateYear.setText(dateToday[2]);
  32. }
Add Comment
Please, Sign In to add comment