Material-calendarview: How to add and view event detail in android material- calendar view?

Created on 31 May 2016  路  14Comments  路  Source: prolificinteractive/material-calendarview

Most helpful comment

@sugeivan swapData is just an example of a name function that should update your list in your ListView adapter or your RecyclerView adapter. Name it what you want.

All 14 comments

from using that, we can add background color to date, I want add description to that event
Anyone help me?

@sugeivan What do you mean by adding a description to an event ? Can you give us a screenshot or a sketch of what you are trying to do ? Im not sure that adding too much information to the calendar will makes the tiles too big and it's not intended. We want the calendar to stay simple and easy to use.

screenshot_2016-06-03-09-39-26
I want like this, when i click the date(in this case 19th) , that display the event of the day (Poson full Moon poya Day). I finished put background color to this date , I want to add event

////////////////My code in Main Activity

   eventDay2 = CalendarDay.from(2016, 04, 18);
    type2.add(eventDay2);
    widget.addDecorator(new EventDecorator(type2, this));

////////////EventDecorator class

public class EventDecorator1 implements DayViewDecorator {

private final HashSet<CalendarDay> dates;
private final Drawable drawable1;


public EventDecorator1(Collection<CalendarDay> dates, Context context) {
    this.dates = new HashSet<>(dates);
    drawable1 = ContextCompat.getDrawable(context, R.drawable.red_circle);

}
@Override
public boolean shouldDecorate(CalendarDay day) {

    return dates.contains(day);
}
@Override
public void decorate(DayViewFacade view) {

    view.setBackgroundDrawable(drawable1);
}

}

This is not a feature from the Material CalendarView but you can do without it.
Just set an OnDateChangedListener. When a new date is selected, populate a list with your events.

widget.setOnDateChangedListener(new OnDateSelectedListener() {
            @Override
            public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
                listAdapter.swapData(loadMyEvents(date.getDate()));
            }
        });
private List<Events> loadMyEvents(Date date) {
        // TODO Load events from Date and return list
        return events;
    }

Use the decorator to display the dot, and that should be it.

What is swapData, I am new in Android, Can u explain more about u mentioned above???

@sugeivan swapData is just an example of a name function that should update your list in your ListView adapter or your RecyclerView adapter. Name it what you want.

widget.setOnDateChangedListener(new OnDateSelectedListener() {
@Override
public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull CalendarDay date, boolean selected) {
listAdapter.swapData(loadMyEvents(date.getDate()));
}
});

private List loadMyEvents(Date date) {
// TODO Load events from Date and return list
return events;
}

hello quentin41500 could you please drop your code here i find it difficult to understand it

how can i display my event decorator after adding an event

@jabes93 This was just an example on how to update a list that displays a list of events based on a date.
You can just add a decorator to the MCV like this: mcv.addDecorator(new EventDecorator(Color.RED, yourDay));.

The sample app contains many examples, please take a look first. Post your bugs or question afterward.

Closing this issue as resolved.

material-calendar-issue.txt

I posted already my concern and it looks the same problem with sugeivan and my second concern is displaying an event base on date created/ selected I already posted my code thank you very much. hope you could see it. Thanks in advance

Can i add multiple DotSpans in a single day?

I want to add a label below some dates in material- calendar view, same it is showing for events. Is there any to do this. Thanks in advance

Can you please add the source code , i mean the MainActivity.java file to add and view the events in this calendar view. It will help me a lot

Was this page helpful?
0 / 5 - 0 ratings