Reputation: 49
I am using a tab-layout to display 3 fragmnets. In those fragments iam displaying the list view in each, by getting the data from json parsing.
But the tabs are really behaving wiered when swiping the content is loaded when ever we slide to that tab and loading one of the three tabs content not exactly what it has to
Upvotes: 0
Views: 64
Reputation: 1302
I think u want to call oncreate of the all 3 fragment only once. But the scenario ur facing is the on create will get called as u swipe; coz that is the property of the fragmentPagerAdapter. Insert this line of code:
ViewPager viewPager;
MyAdapter mViewPgAdapter = new MyAdapter(getChildFragmentManager());
viewPager.setOffscreenPageLimit(totalNumOfFragmentsUHave);//as mentioned u have 3
viewPager.setAdapter(mViewPgAdapter);
The setOffScreenPageLimit() is the key to your problem
Upvotes: 2
Reputation: 1150
When you are using tabLayout
with fragments (I suppose you are using a FragmentPagerAdapter
), by default the system will load in memory the tab that will be displayed and also the previous and the next one. Is that what you mean?
Upvotes: 0