android - Tab Disappear when start new activity -
i developing android application having multiple tabs.
now in launcher activity tabs display , can navigate through tabs. if call activity(which wanted show tab) on button clicked tabs seems disappear.
please refer given code , let me know if doing wrong.
this main tabactivity
public class mytabactivity extends tabactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_tab); tabhost tabhost=gettabhost(); tabspec deshtab=tabhost.newtabspec("deshboard"); deshtab.setindicator("deshboard"); intent deshboardintent=new intent(this,deshboardactivity.class); deshtab.setcontent(deshboardintent); tabhost.addtab(deshtab); tabspec clienttab=tabhost.newtabspec("client"); clienttab.setindicator("client"); intent intent=new intent(this,clientactivity.class); clienttab.setcontent(intent); tabhost.addtab(clienttab); } }
now wanted start client activity like
void onbuttonclick(view view) { int id = view.getid(); switch(id) { case r.id.client_btn: intent clientintent = new intent(deshboardactivity.this,clientactivity.class); startactivity(clientintent); break; } }
but when click button starts new activity not in tab. should display activity in tab on button click also.?
below code clientactivity wanted display tab.
public class clientactivity extends activity { private databasehandler dbhandler; private listview clientlistview ; private baseadapter listadapter; tabhost tabhost; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.clientactivity); dbhandler = new databasehandler(this); final list<client> clientlist = dbhandler.getallclient(); clientlistview = (listview)findviewbyid(r.id.client_list); listadapter = new clientlistadapter(this, clientlist); clientlistview.setadapter(listadapter); clientlistview.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> parent, view view,int position, long id) { client client = clientlist.get(position); toast.maketext(getapplicationcontext(), client.getfirstname(), toast.length_long).show(); intent clientinfointent = new intent(getapplicationcontext(), clientinfoactivity.class); clientinfointent.putextra("client",client); startactivity(clientinfointent); //finish(); } }); } }
that's because clientactivity launched on top of tabactivity. way tabbar not shown anymore. suggest use fragments clientactivity.
a tutorial how use fragments: http://developer.android.com/guide/components/fragments.html
Comments
Post a Comment