Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ViewPager fragment is not working in 2nd time inside navigation drawer fragment properly

I have Navigation Drawer in which there is one fragment for the Tab Viewer. In tabviewer, I am using ViewPager which also in the Fragment. The code for ViewPager is

    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);

The tabs is coming in the first click in the navigation drawer with its content but for the second time the only title of tabs is coming without its layout. Layout is not coming and swipe is also not working between different tabs? Why its working for the first time but not for the rest? I am attaching the images for two different click on same navigation drawer fragment. This is first click so the layout is coming perfectly. enter image description here

This in 2nd attempt to click on the same fragment but only background is coming without any layout content.

enter image description here

Help to get rid of this problem.

like image 622
paudel.sulav Avatar asked Feb 05 '16 19:02

paudel.sulav


2 Answers

use

getChildFragmentManager()

instead of

((FragmentActivity)getActivity()).getSupportFragmentManager()
like image 143
JAAD Avatar answered Oct 13 '22 20:10

JAAD


I used getFragementManager(). So I was able to reload fragments used in tabs. Now, I used getChildFragmentManager(). It works fine.

like image 33
user8338075 Avatar answered Oct 13 '22 20:10

user8338075