ViewPager fragment does not work for the 2nd time inside the navigation box fragment

I have a Navigation Drawer in which there is one snippet for a Tab Viewer . In tabviewer, I use ViewPager , which is also in Fragment . Code for ViewPager -

  viewPager = (ViewPager) rootView.findViewById(R.id.pager); viewPager.setAdapter(new TabsPagerAdapter(((FragmentActivity)getActivity()).getSupportFragmentManager())); PagerSlidingTabStrip tabsStrip = (PagerSlidingTabStrip) rootView.findViewById(R.id.tabs); tabsStrip.setViewPager(viewPager); 

Tabs are displayed in the first click in the navigation box with its contents, but the second time the only name of the tabs goes without its layout. The layout doesnโ€™t fit and the swipe also doesnโ€™t work between different tabs? Why is it working for the first time, but not for the rest? I attach images for two different clicks on the same fragment of the navigation box. This is the first click, so the layout fits perfectly. enter image description here

This is in the second attempt to click on the same fragment, but only the background image comes out without the contents of the layout.

enter image description here

Help get rid of this problem.

+5
source share
3 answers

using

 getChildFragmentManager() 

instead

 ((FragmentActivity)getActivity()).getSupportFragmentManager() 
+13
source

I used getFragementManager (). Therefore, I was able to reload the fragments used in the tabs. Now I used getChildFragmentManager (). It works great.

+1
source

He works for me.

try using:

 getChildFragmentManager() 

instead:

 ((FragmentActivity)getActivity()).getSupportFragmentManager() 
0
source

Source: https://habr.com/ru/post/1242401/


All Articles