tabbar - android setting default tab in tab-activity -
android tabactivity launches fragmentactivity associated first tab added in sequence before setting tabhost.setcurretntab(4);
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.tab_main); try { datasource.objcontext = this.getapplicationcontext(); datasource.objtabbaractivity = this; datasource.objsharedpreferences = this.getsharedpreferences("com.example", context.mode_private); if(networkstat) { new locationupdates(this); this.settabs(); } else { log.d("in tabbaractivity", "network failure"); toast.maketext(this.getapplicationcontext(), "network failure", toast.length_short).show(); } } catch(exception ex) { } } private void settabs() { addtab("clubs", r.drawable.tab_clubs, fragmentstackclubsactivity.class); addtab("events", r.drawable.tab_events, fragmentstackeventsactivity.class); addtab("rate", r.drawable.tab_rate, fragmentstackrateactivity.class); addtab("loyalty", r.drawable.tab_loyalty, fragmentstackloyaltyactivity.class); addtab("setting", r.drawable.tab_settings, fragmentstacksettingsactivity.class); if(datasource.objsharedpreferences.getstring(datasource.login_tag, "false").equalsignorecase("false")) { gettabhost().setcurrenttab(4); datasource.disabletabbar(); } else { } } private void addtab(string labelid, int drawableid, class<?> c) { tabhost tabhost = gettabhost(); intent intent = new intent(this, c); tabhost.tabspec spec = tabhost.newtabspec("tab" + labelid); view tabindicator = layoutinflater.from(this).inflate(r.layout.tab_indicator, gettabwidget(), false); textview title = (textview) tabindicator.findviewbyid(r.id.title); title.settext(labelid); imageview icon = (imageview) tabindicator.findviewbyid(r.id.icon); icon.setimageresource(drawableid); spec.setindicator(tabindicator); spec.setcontent(intent); tabhost.addtab(spec); }
but problem starts first tab , switches 5th tab in way thread gets started first tab , that's don't want i.e if user not logged in wanna redirect user login(settings) tab. in regard highly appreciated......
public void setcurrenttab (int index) public void setcurrenttabbytag (string tag)
you can this
if (isnotlogin) { tabhost.setcurrenttabbytag("setting"); }
after addtab()
http://developer.android.com/reference/android/widget/tabhost.html#setcurrenttab(int)
Comments
Post a Comment