CosmoCalendar icon indicating copy to clipboard operation
CosmoCalendar copied to clipboard

Adding Marker in Calendar using Connected Days for events, task, note, etc.

Open abdulrahmankazi opened this issue 4 years ago • 3 comments

### SOLUTION TO ADD EVENTS

Screenshot_1622012396

I was searching for a way to add marker on particular dates, but didn't find any. However as you can see in above image, I have managed to add marker to Calendar dates. I have used addConnectedDays() provided by Cosmo Calendar. Markers can be added on TOP & BOTTOM of date. Sharing code I used:

                    Set<Long> days = new TreeSet<>();
                    e.g. 
                    String date1 = "05-18-2021";
                    String date2 = "05-09-2021";
                    //........

                    SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd-yyyy");
                    try {
                        Date mDate1 = sdf1.parse(date1);
                        long timeInMilliseconds1 = mDate1.getTime();

                        
                        Date mDate2 = sdf1.parse(date2);
                        long timeInMilliseconds2 = mDate2.getTime();

                        days.add(timeInMilliseconds1);
                        days.add(timeInMilliseconds2);
                        // can add more days to set

                    } catch (Exception e) {
                        Log.e("DateException", e.getMessage());
                    }
          
                int textColor = Color.parseColor("#0063B0");
                int selectedTextColor = Color.parseColor("#FFFFFF");
                int disabledTextColor = Color.parseColor("#ff8000");
                ConnectedDays connectedDays = new ConnectedDays(days, textColor, selectedTextColor, disabledTextColor);

                //Add Connect days to calendar
                calendarView.addConnectedDays(connectedDays);

                calendarView.setConnectedDayIconRes(R.drawable.ic_baseline_star_24);   // Drawable
                calendarView.setConnectedDayIconPosition(ConnectedDayIconPosition.TOP);// TOP & BOTTOM
                calendarView.update();

abdulrahmankazi avatar May 27 '21 13:05 abdulrahmankazi

the calendar keeps to the current month, how do I stop this ?

sourav-android avatar Feb 11 '22 09:02 sourav-android

Thanks for providing the solution. I want multiple markers for that date to be created, do you know how?

TakJIAe avatar Apr 01 '22 06:04 TakJIAe

Better to use https://github.com/kizitonwose/CalendarView or https://github.com/huanghaibin-dev/CalendarView

abdulrahmankazi avatar Apr 21 '22 05:04 abdulrahmankazi