ExtendedCalendarView icon indicating copy to clipboard operation
ExtendedCalendarView copied to clipboard

Add events without using on Listener - added when view is created

Open llennoco opened this issue 8 years ago • 0 comments

Hi there,

I'm looking to add an event to the extendedCalendarView without using a listener. I have calculated the date and time in my onCreateView and wish to display this specific date on the calendar when the view is created.

`ExtendedCalendarView calendar = (ExtendedCalendarView) v.findViewById(R.id.calendar);

        try {
            ContentValues values = new ContentValues();
            values.put(CalendarProvider.COLOR, Event.COLOR_RED);
            values.put(CalendarProvider.DESCRIPTION, "Some Description");
            values.put(CalendarProvider.LOCATION, "Some location); ");
            values.put(CalendarProvider.EVENT, " Event name");

            sdf = new SimpleDateFormat("yyyy-MM-dd/HH:mm:ss");

            Date mDate = sdf.parse(combineString);
            long timeInMilliseconds = mDate.getTime();

            long timeNextInjection = timeInMilliseconds + 1210000000;
            Log.d("Test", "Time : " + timeNextInjection);
            TimeZone tz = TimeZone.getDefault();
            Calendar cal = Calendar.getInstance();


            cal.set(mDate.getYear(), mDate.getMonth(), (mDate.getDate()), mDate.getHours(), mDate.getMinutes());
            int StartDayJulian = Time.getJulianDay(cal.getTimeInMillis(), TimeUnit.MILLISECONDS.toSeconds(tz.getOffset(cal.getTimeInMillis())));
            values.put(CalendarProvider.START, cal.getTimeInMillis());
            values.put(CalendarProvider.START_DAY, StartDayJulian);


            mDate.setDate(mDate.getDate() + 14);
            cal.set(mDate.getYear(), mDate.getMonth(), (mDate.getDate()), mDate.getHours(), mDate.getMinutes());


           mDate.getMinutes());
            int endDayJulian = Time.getJulianDay(cal.getTimeInMillis(), TimeUnit.MILLISECONDS.toSeconds(tz.getOffset(cal.getTimeInMillis())));

            values.put(CalendarProvider.END, cal.getTimeInMillis());
            values.put(CalendarProvider.END_DAY, endDayJulian);

            Uri uri = getActivity().getContentResolver().insert(CalendarProvider.CONTENT_URI, values);

`

I have not edited the original files provided yet.

Any help would be so appreciated! I've been looking for a solution for a long time

llennoco avatar Feb 21 '17 16:02 llennoco