Skip to content Skip to sidebar Skip to footer

Callbacks For When A Fragment In A Viewpager Is Set As Current Page

I have a viewpager, it has 5 fragments page. I can switch between each fragment by tapping a navigation button. Now, what I'm trying to achieve is to refresh 1 of the page when ent

Solution 1:

Since you don't need any kind of caching, it's probably a good idea for you to use viewPager.setOffscreenPageLimit(0) so pages won't be loaded in background, and onResume will be called only when page is actually displayed.UPD: Thanks, Yarh, for pointing out that setOffscreenPageLimit(0) doesn't work. Sorry for that.

If this doesn't work for you, use viewPager.addOnPageChangeListener(listener) - onPageSelected(position) method should help.

Solution 2:

Post a Comment for "Callbacks For When A Fragment In A Viewpager Is Set As Current Page"