Re: Question about setting weekview event
See original GitHub issueHello,
This is with reference to the issue I opened earlier, with the same title. I cannot reopen the issue, because it was not closed by me. Hence opening a new issue:
Question : Is there a way to set the list of events in WeekView other than returning List of WeekViewEvents in onMonthChange() ?
Your solution:
Currently the week view does not provide a ready-made solution for async event loading. But there is a simple hack. Use the following code to achieve what you want.
@Override public List onMonthChange(int newYear, int newMonth) { // Populate the week view with some events. List events = new ArrayList();
// Fetch events for the date user selected.
fetchEventsinBackground();
}
// Callback when fetchEvents finishes. public void setEventList(Activity activity, final List eventModels) {
// Hide the progress dialog.
if(mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
}
// Refresh the week view.
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
// Store the returned events in a global variable for later use.
mEventModels = eventModels;
// This line will trigger the method 'onMonthChange()' again.
mWeekView.notifyDatasetChanged();
}
});
}
@Override public List<WeekViewEvent> onMonthChange(int year, int month) { // TODO Be sure to check if the variables year and month equals the year and month of the events of mEventModels. return getWeekViewEventsFromEventModels(mEventModels); }
Thank you for the response, however it did not work for me.
Java doesn’t support 2 methods with same signature, so I can’t have something like this in the same class:
@Override public List<WeekViewEvent> onMonthChange(int year, int month) { // TODO Be sure to check if the variables year and month equals the year and month of the events of mEventModels. return getWeekViewEventsFromEventModels(mEventModels); } @Override public List onMonthChange(int newYear, int newMonth) { // Populate the week view with some events. List events = new ArrayList();
// Fetch events for the date user selected.
fetchEventsinBackground();
} If mWeekView.notifyDatasetChanged(); triggers onMonthChange() again, then it results in an infinite loop with fetchEventsinBackground() being called again & again!
Is there a better way out ? Thanks for all the help!
Issue Analytics
- State:
- Created 9 years ago
- Comments:23 (9 by maintainers)
Top GitHub Comments
Sorry. I should have been more precise about the code. Here, check out the new code.
@waynem81 You’ll probably have to convert your bean to an instance of WeekViewEvent