Reputation: 3647
I have a viewpager in my app with 4 tabs. I know I can do setOffscreenPageLimit(3)
to retain all the pages from reloads. but my problem now is that all 4 tabs need to send request to server and that take some time, especially when all 4 requests are sent at the same time. Is there a way that I can do like setOffscreenPageLimit(0)
which makes the app only loads the current page but retain the page when swipe happen?
Upvotes: 0
Views: 265
Reputation: 18977
Is there a way that I can do like setOffscreenPageLimit(0) which makes the app only loads the current page but retain the page when swipe happen?
No you can not, in order to have a better UX android dose not allow to set it to 0, so the default value and the lowest one is 1 which means it loads your off screen fragments of left and right of your current fragment.
what should you do?
3 different solutions I can offer you:
1) Send your request to server at the function onPageSelected(int position)
2) if you are using actionBar
tab use onTabSelected
and send your request to server.
3) send your request at the onResume
of your fragment by using setUserVisibleHint
and getUserVisibleHint
function to determine when your fragment is really visible to your user so send it at the right time.
Upvotes: 2