-3

I've used ViewPager and TabLayout in my app, and the items in the TabLayout are dynamically received and fetched from the server. When the item is clicked on the TabLayout, items are fetched from the server and displayed inside the screen.

But when I click on the fourth tab and return again, the items are retrieved from the server, which means the update fails. What do you recommend to prevent this?

Hugues M.
  • 19,846
  • 6
  • 37
  • 65
  • This link will help you solve your problem. https://stackoverflow.com/questions/20702333/refresh-fragment-at-reload – LatheElHafy Sep 03 '17 at 20:41

1 Answers1

0

Your problem can be simply solved by this line of code. The general characteristics of viewpager is when you are in page 1 then it loads page 2 and in page 2 it loads page 3. So on coming back when you are in page 2 it loads page 1 again. This single line will solve your issue. It loads all three page at once .

mViewPager.setOffscreenPageLimit(3); //here 3 means number of pages
taman neupane
  • 938
  • 9
  • 18