Android - how to auto switch tab in tabhost -
i have tabhost 3 tabs. in tab 3 have activity: testactivity. in activity, have button. when click button in tab 3, want tabhost switch in tab 1. should switch automatically; i'm don't click tab 1. how can this?
public class tabhostactivity extends activity{ public tabhost tabhost; private resources res; intent intent; tabhost.tabspec spec; private localactivitymanager mlocalactivitymanager; protected int currenttab; @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.tabhost); tabhost = (tabhost) findviewbyid(r.id.tabhost); mlocalactivitymanager = new localactivitymanager(this, false); mlocalactivitymanager.dispatchcreate(savedinstancestate); tabhost.setup(mlocalactivitymanager); res = getresources(); intent = new intent().setclass(this, spinneractivity.class); spec = tabhost.newtabspec("artists"); spec.setindicator("sinner", null); spec.setcontent(intent); tabhost.addtab(spec); intent = new intent().setclass(this, sonandroidactivity.class); spec = tabhost.newtabspec("main"); spec.setindicator("main",res.getdrawable(r.drawable.ios_logo)); spec.setcontent(intent); tabhost.addtab(spec); intent = new intent().setclass(this, testactiviy.class); spec = tabhost.newtabspec("spinner"); spec.setindicator("test", null); spec.setcontent(intent); tabhost.addtab(spec); } tabhost.setontabchangedlistener(new ontabchangelistener() { @override public void ontabchanged(string tabid) { log.v("tag", "click:" + tabhost.getcurrenttab()); currenttab = tabhost.getcurrenttab(); } and event activity tab 3:
public class testactiviy extends tabhostactivity{ @override protected void oncreate(bundle savedinstancestate) { // todo auto-generated method stub super.oncreate(savedinstancestate); setcontentview(r.layout.test); } public void btn_onclick(view v) { tabhost.setcurrenttab(0); log.v("tag", "clickkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk"); } }
public void btn_onclick(view v) { localactivitymanager l = new localactivitymanager (); l.tabhost.setcurrenttab(0); }
Comments
Post a Comment