Reputation: 2139
I'm trying to catch a moment then user has switched to the next Fragemnt in FragmentStatePagerAdapter. I have tried to override onPause() function inside my Fragment, but it does not called, until user has switched two pages (probably, because of animation).
I also have tried to override the onResume() function, and have found out, that it is called for two fragments at the same time.
Is there a function what should indicate witch fragment being switched on?
I'm thinking now to override FragmentStatePagerAdapter getItem and keep the list of created items, so I can at least refer to Fragment from a separate function, but is there is a better way?
Thanks
Upvotes: 0
Views: 68
Reputation: 1007265
I'm trying to catch a moment then user has switched to the next Fragemnt in FragmentStatePagerAdapter.
IMHO, that is not the job of FragmentStatePagerAdapter
, but rather of whatever activity or fragment hosts your ViewPager
.
Is there a function what should indicate witch fragment being switched on?
Call setOnPageChangedListener()
on your ViewPager
to register an OnPageChangedListener
, to find out when the user changes pages.
Upvotes: 2