Android Tab Help. How to set 2nd tab as default when app opens? -


i have created app 3 tabs. app works fine want 2nd tab selected , loaded when app opens. how can set that?

here code :

public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_main);          tabhost tabhost = gettabhost();            // tab home         tabspec homespec = tabhost.newtabspec("home");         // setting title , icon tab         homespec.setindicator("home",getresources().getdrawable(r.drawable.icons_home_tab));         intent photosintent = new intent(this, homeactivity.class);         homespec.setcontent(photosintent);          // tab child         tabspec childspec = tabhost.newtabspec("child");         childspec.setindicator("child",getresources().getdrawable(r.drawable.icons_child_tab));         intent homeintent = new intent(this, childactivity.class);         childspec.setcontent(homeintent);          // tab account         tabspec accspec = tabhost.newtabspec("account");         accspec.setindicator("account",getresources().getdrawable(r.drawable.icons_account_tab));         intent accintent = new intent(this, accountactivity.class);         accspec.setcontent(accintent);          // adding tabspec tabhost         tabhost.addtab(homespec); // adding home tab         tabhost.addtab(childspec); // adding child tab         tabhost.addtab(accspec); //adding account tab         } 

use method set current tab after added tab in tabhost

tabhost.setcurrenttab(1);  // here pass tab index starting 0 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -