android - Struggling with a top level FragmentPagerAdapter containing a Fragment with its own FragmentPagerAdapter -
have 2 level ui, top level has tab strip powered fragmentpageradapter. 1 of fragments in turn has 2nd level fragmentpageradapter , own tab strip carrying couple of "sub"fragments. now, sub fragments display when first time top level tabs traversed. "sub"fragments not display upon 2nd iteration
here how subtabpager adapter created in 1 of fragments exist @ top level
public final class mainleveltabfragment extends fragment {
private subpagetabspageradapter msubpagepageradapter; private viewpager msubpageviewpager; private slidingtablayout mslidingtablayout; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = null; bundle bundle = getarguments(); rootview = inflater.inflate(r.layout.fragment_tab_main_level, container, false); msubpageviewpager = (viewpager) rootview.findviewbyid(r.id.subpage_screen_tabs_pager); mslidingtablayout = (slidingtablayout) rootview.findviewbyid(r.id.sliding_tabs); msubpagepageradapter = new subpagetabspageradapter(getsupportfragmentmanager, getactivity()); msubpageviewpager.setadapter(msubpagepageradapter); return rootview; }
the subpagetabspageradapter code looks this
public class subpagetabspageradapter extends fragmentpageradapter { private context mcontext; private cursor mcursor; public subpagetabspageradapter(fragmentmanager fm, context context) { super(fm); mcontext = context; } @override public fragment getitem(int position) { if (null == mcursor) return null; mcursor.movetoposition(position); fragment fragment = new subtabfragment(); fragment.setarguments(args); return fragment; } @override public int getcount() { return (null != mcursor) ? mcursor.getcount() : 0; } @override public charsequence getpagetitle(int position) { if (null == mcursor) return null; mcursor.movetoposition(position); return "title"; } public void swapcursor(cursor c) { if (mcursor == c) return; mcursor = c; notifydatasetchanged(); } }
i think might have use getchildfragmentmanager()
instead of getsupportfragmentmanager()
in subpagetabspageradapter
constructor.