Saving tab information after swipe

大憨熊 提交于 2020-01-02 12:47:15

问题


I have 3 tabs in my application. In my first tab I need to read JSON data from URL and using the user location. It takes about 2-3 seconds to load the page. My problem starts when I implemented tabs, and now every time im swiping next and back, the info is re-fetched.

I tried the following solution: I moved my method to the MainActivity, and created a variable named "isUpdated" and updated it to 1 if the info has been fetched successfully. since then, the tab data is gone after swiping and it shows blank empty tab. I understand that the tab data is wiped after swiping to another tab, but I need to save the tab content.

How I can save the tab information and show it after the user swiped to the next tabs, without re-fetching the data over and over again?


回答1:


if you are using ViewPager then set your off screen page limit to something different

for example

mViewPager.setOffscreenPageLimit(2);

should be enough for 3 tabs



来源:https://stackoverflow.com/questions/32212032/saving-tab-information-after-swipe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!