Reputation: 7519
I'm not sure how else to word the title, but the viewpager in my application works as it should - instantiating the current view along with left and right views.
What I would like to know is if I can display content of a non-viewpager element (in this case a listview) on just the first load of the viewpager and then update accordingly as the viewapager scrolls.
Relevant code:
_calendar.set(Calendar.MONTH, m);
_calendar.set(Calendar.YEAR, y);
holdTodaysDate.set(Calendar.MONTH, m);
holdTodaysDate.set(Calendar.YEAR, y);
_calendar = holdTodaysDate;
_calendar.add(Calendar.MONTH, offset-1);
month = _calendar.get(Calendar.MONTH)+1;
year = _calendar.get(Calendar.YEAR);
Log.d("Calendar", "Month Year" + month + " " + year);
eventsSummary.onEventsNavigation(month, year, date_value);
--calendar adapter--
The problem is eventsSummary
(non-viewpager element) has to load using the initial month value when the viewpager loads, but since the viewpager loads thrice, month+1 is displayed in eventsSummary
.
For example, February is the current month and it does display February the first time the viewpager loads as I can see in the log, but the viewpager instantiates the next and previous views too - so January is loaded and March. The eventsSummary
finally displays the events for March while the main calendar (which is the ViewPager element) displays February.
How can I get eventsSummary
to display the events for February, rather than March and then update its view with the month the user has swiped to?
I'm passing information between the fragments eventsSummary
and the Calendar ViewPager container using the approach shown here.
Upvotes: 0
Views: 512
Reputation: 38252
Am I correct in understanding that you are setting the date in each fragment's onCreate()
?
Perhaps you should instead observe what page the ViewPager is displaying, and trigger events through an OnPageChangeListener.
Upvotes: 1