java - How to initialize tab content when app is initialized -
i have app has 2 tabs. each tab loads xml file (fairly large, maybe 400 item rss file).
by default tab doesn't xml until it's clicked on. wanted way load when app first opened.
here main view:
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); resources res = getresources(); // resource object drawables tabhost tabhost = gettabhost(); // activity tabhost tabhost.tabspec spec; // resusable tabspec each tab intent intent; // reusable intent each tab // audio feed intent = new intent().setclass(this, audiofeed.class); spec = tabhost.newtabspec("audio").setindicator("", res.getdrawable(r.drawable.ic_tab_audio)) .setcontent(intent); tabhost.addtab(spec); // video feed intent = new intent().setclass(this, videofeed.class); spec = tabhost.newtabspec("video").setindicator("", res.getdrawable(r.drawable.ic_tab_video)) .setcontent(intent); tabhost.addtab(spec); tabhost.setcurrenttab(0); //todo: remember tab user last on }
i use tabhost.setcurrenttab(x) or tabhost.setcurrenttabbytag(x).
mtabhost.setcurrenttab(1); mtabhost.setcurrenttab(0);
for initialization use tabhost.ontabchangelistener.
private ontabchangelistener montabchangelistener = new ontabchangelistener() { @override public void ontabchanged(string tag) { if (fbintent.extra_xx.equals(tag)) { // current tab xx. ... if xx not init -> ... } else if (fbintent.extra_yy.equals(tag)) { // current tab yy. ... } } };
Comments
Post a Comment