Reputation: 5850
I'm trying to add a ViewPager for each tab to display images. For the first tab on the launch, everything is fine. The Fragments are being fetched with the help of custom FragmentStatePagerAdapter. I'm instantiating a new ViewPager object in CreateTabContent method.
The problem occurs when I click on Tab 2, after the contents of first tab are displayed. I set a new FragmentStatePagerAdapter object on the new ViewPager object. Again all the methods like getCount, getItem, getItemPosition execute properly, but the objects are do not attach to the ViewPager.
On checking the hierarchviewer, I found out that NoSaveStateFrameLayout objects are not being created.
Thanks.
Note: I've implemented notifyDataSetChanged.
The problem occurs
Upvotes: 0
Views: 372
Reputation: 5850
I found out the solution. I checked the hierarchyviewer, again, carefully and found out that NoSaveStateFrameLayout object, which should be attached to the ViewPager for the next tab was being attached to the first ViewPager. So, I detached the ViewPager on tab 1 when next tab is clicked using this code:
FrameLayout frameLayout = mTabHost.getTabContentView();
frameLayout.removeViewAt(index);
Now, Only one ViewPager object exists and everything is working great.
Upvotes: 1