android - Create Multiple Fragments Dynamically for Dynamic Tabs -


i have requirement , not know how accomplish this. can guys me out done. below flow is

i have main category list, user can tap sub categories (fetch server) , based on result displaying list of subcategories child category well. next creating tabs based on child categories.

now problem creating fragments number of tabs. childs can 1 n number, know best way create fragments dynamically. once each fragment have display list of items fetched server.

thank you

you can use following code snap

you need create corresponding layout xml

    viewpager pager;     viewpageradapter adapter;     private list<fragment>  fragments;     arraylist<string> titles;          @override         protected void oncreate(bundle savedinstancestate) {             fragments = new arraylist<fragment>();          titles= new arraylist<string>();         pager = (viewpager) findviewbyid(r.id.pager);         adapter = new viewpageradapter(getsupportfragmentmanager(), titles, fragments);         pager.setadapter(adapter);         (int i=0;i<numoffragments;i++){                 fragments.add(new demofragment());              }         adapter.notifydatasetchanged();           } 

you may need more adjustments numoffragments using , have make fragment can used childs

hope wil help.


Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -