mvasco
mvasco

Reputation: 5101

Retrieving string from List

I am using a third party library to show dates on a custom calendar.

I need to retrieve some information when the user clicks on a day.

This is the code for onDayClick method:

 public void onDayClick(Date dateClicked) {
                List<Event> events = compactCalendarView.getEvents(dateClicked);
                Log.d(TAG, "Day was clicked: " + dateClicked + " with events " + events);


            }

And this is the output from the log for this method:

Day was clicked: Wed Mar 13 00:00:00 GMT+01:00 2019 with events [Event{color=-16711936, timeInMillis=1552431600000, data=Some extra data that I want to store.}]

I would like to retrieve the field data from that string...

Upvotes: 0

Views: 30

Answers (1)

AlexTa
AlexTa

Reputation: 5251

According CompactCalendarView library, data object type is Object. So, to retrieve that field, just iterate through event list, then access data field:

List<Event> events = compactCalendarView.getEvents(dateClicked);
for (Event event : events) {
    Object data = event.getData();
    // Access to other event properties
    int color = event.getColor();
    long timeInMillis = event.getTimeInMillis();
}

Upvotes: 3

Related Questions