Giacomo De Bacco Giacomo De Bacco - 2 months ago 35
Java Question

Show event information with ExtendedCalendarView

I'm trying to create a custom calendar for show events and relative informations in my app.
But I don't know how to show this informations. That's the code of the calendar:

@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ExtendedCalendarView calendar = (ExtendedCalendarView)findViewById(R.id.calendar);
ContentValues values = new ContentValues();
values.put(CalendarProvider.COLOR, Event.COLOR_BLUE);
values.put(CalendarProvider.DESCRIPTION, "Some Description");
values.put(CalendarProvider.LOCATION, "Some location");
values.put(CalendarProvider.EVENT, "Event name");

Calendar cal = Calendar.getInstance();
TimeZone tz = TimeZone.getDefault();
cal.set(startDayYear, startDayMonth, startDayDay, startTimeHour, startTimeMin);
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);

cal.set(endDayYear, endDayMonth, endDayDay, endTimeHour, endTimeMin);
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 = getContentResolver().insert(CalendarProvider.CONTENT_URI, values);
}


I can see the calendar and the Event , but probably i've to implement some "Onclick" method for display the infomations. Anyone that are using this library that can help me? Beacuse i can't find any information about.
Thank you.

Answer

I've found the answer by myself.

cal.setOnDayClickListener(new OnDayClickListener() {
        @Override
        public void onDayClicked(AdapterView<?> adapter, View view,
                int position, long id, Day day) {

            dayIsClicked = true;
            clickedDay = day;
            getScheduleDetails(day);

            list.setAdapter(new ListaAdapter(context, R.layout.itemlist,
                            itemsList));

                }

            }

    });

private void getScheduleDetails(Day day) {

itemsList = new ArrayList();

for (Event e : day.getEvents())
{   
    itemsList.add(e);
}

}