android - How do I replace the fragment from one of the tabs in a TabAdapter? -
while realize nested fragments not option still have issue cannot figure out answer to.
i'm using actionbarsherlock's fragmentstabpager example create interface possible page through tabs swiping rather clicking on tabs. problem 1 of these tabs consists of listview. when listview clicked, different fragment containing new list(with data based on item clicked) launched. how accomplish ?
i figured might need bit of cose baseactivity(the 1 viewpager , tabsadapter
*snippet* public class baseactivity extends sherlockfragmentactivity { tabhost mtabhost; viewpager mviewpager; tabsadapter mtabsadapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.fragment_tabs_pager); mtabhost = (tabhost)findviewbyid(android.r.id.tabhost); mtabhost.setup(); mviewpager = (viewpager)findviewbyid(r.id.pager); mtabsadapter = new tabsadapter(this, mtabhost, mviewpager); mtabsadapter.addtab(mtabhost.newtabspec("home").setindicator("home"), fragmentstacksupport.countingfragment.class, null); mtabsadapter.addtab(mtabhost.newtabspec("players").setindicator("players"), playerrankingfragment.class, null); mtabsadapter.addtab(mtabhost.newtabspec("teams").setindicator("teams"), federationranksfragment.class, null); if (savedinstancestate != null) { mtabhost.setcurrenttabbytag(savedinstancestate.getstring("tab")); } } /** * helper class implements management of tabs , * details of connecting viewpager associated tabhost. relies on * trick. tab host has simple api supplying view or * intent each tab show. not sufficient switching * between pages. instead make content part of tab host * 0dp high (it not shown) , tabsadapter supplies own dummy * view show tab content. listens changes in tabs, , takes * care of switch correct paged in viewpager whenever selected * tab changes. */ public static class tabsadapter extends fragmentpageradapter implements tabhost.ontabchangelistener, viewpager.onpagechangelistener { private final context mcontext; private final tabhost mtabhost; private final viewpager mviewpager; private final arraylist<tabinfo> mtabs = new arraylist<tabinfo>(); static final class tabinfo { private final string tag; private final class<?> clss; private final bundle args; tabinfo(string _tag, class<?> _class, bundle _args) { tag = _tag; clss = _class; args = _args; } } *snippet*
baseactivity -> tab "teams" -> teams listview(alliancefragment) -> teams item clicked -> players listview(playersfragment).
and lastly here's screenshot of app in question:
btw, latest support library, nested fragment support got added. see getchildfragmentmanager() method. careful memory leaks. still playing around them. used pagertabstrip , viewpager. works well.
Comments
Post a Comment