Android :adding tabs in fragments using view pager -
i have implement swiping in view pager 3 pages i.e fragment 1,fragment 2 , fragment 3. want add tab-host, contains 5 tabs different views in fragment 3. have 7 pages in view pager. tabs should visible in fragment 3 only.
how can add tabs in fragment 3?
public class homeactivity extends fragmentactivity { // page adapter between fragment list , view pager public static pageradapter mpageradapter; // view pager public viewpager mpager; // activity data public string p2text, p3text; public static list<fragment> fragments;// = buildfragments(); // / arraylist<string> categories = {"1","2","3","4","5","6","7","8"}; arraylist<string> categories = new arraylist<string>(); static final string log_tag = "homeactivity"; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); fragments = new arraylist<android.support.v4.app.fragment>(); categories.add("1"); categories.add("2"); categories.add("3"); categories.add("4"); categories.add("5"); categories.add("6"); categories.add("7"); addfragments(fragmentmore.class.getname(), 1); addfragments(fragmentmain.class.getname(), 2); addfragments(fragmentchatview.class.getname(), 3); mpager = (viewpager) super.findviewbyid(r.id.pager); mpageradapter = new pageradapter(this, getsupportfragmentmanager(), fragments, categories); mpager.setadapter(mpageradapter); mpager.setcurrentitem(1); } public void addfragments(string classname, int position) { // list<android.support.v4.app.fragment> fragments = new // arraylist<android.support.v4.app.fragment>(); // (int = 0; i<categories.size(); i++) { bundle b = new bundle(); b.putint("position", position); fragments.add(fragment.instantiate(this, classname, b)); // } // return fragments; } public void removefragments(string classname, int position) { // list<android.support.v4.app.fragment> fragments = new // arraylist<android.support.v4.app.fragment>(); // (int = 0; i<categories.size(); i++) { bundle b = new bundle(); b.putint("position", position); fragments.remove(fragment.instantiate(this, classname, b)); // } // return fragments; } private list<android.support.v4.app.fragment> buildfragments() { list<android.support.v4.app.fragment> fragments = new arraylist<android.support.v4.app.fragment>(); (int = 0; < categories.size(); i++) { bundle b = new bundle(); b.putint("position", i); fragments.add(fragment.instantiate(this, fragmentsearch.class.getname(), b)); } return fragments; } @override public void onresume() { super.onresume(); log.e(log_tag, "onresume"); } @override public void onpause() { super.onpause(); log.e(log_tag, "onpause"); } }
i think trying done here:
- api demos code: fragmentnestingtabs , fragmenttabsfragment
- app android functionalities here in app/fragment/nesting tabs/ (last tab)
with these 2 links should able develop looking for.
hope helps!
Comments
Post a Comment