setCurrentTab of a tabHost

后端 未结 3 1975
别跟我提以往
别跟我提以往 2021-01-07 13:19

I\'m asking if we can call a setCurrentTab on a tabhost from another class than the class that contains the tabhost and tabspecs?

Can we put

tabHost.         


        
3条回答
  •  無奈伤痛
    2021-01-07 14:15

    But if you are in another activity, you won't see the tabs anyway will you?

    I had a similar problem with a ListView which started the tabHost activity onItemClick to get that working, i passed the tabNumber i wanted to display, through the intent, then used setCurrentTab to set the current tab to the passed tab number. Not sure if this would work for you though.

    EDIT: Here is how i did it:

    Intent i = new Intent(this, TabHostActivity.class);
    i.putExtra("TabNumber", tabNumberToBeSelected); //tabNumberToBeSelected is an int
    startActivity(i);
    

    and then in the tabHost activity:

    int tabNumber = getIntent().getIntExtra("TabNumber", 0);
    
    //tabHost code goes here
    
    tabHost.setCurrentTab(tabNumber);    
    

提交回复
热议问题