开发者

How to access a tabhost with multiple tabs of the same Activity?

开发者 https://www.devze.com 2023-02-17 08:55 出处:网络
I\'m developing an \"Scorer Application\" for a board game. The game can host between 2 and 8 players. So I have created a Tabhost with 8 tabs of the same activity(player.class). And it works :)

I'm developing an "Scorer Application" for a board game. The game can host between 2 and 8 players. So I have created a Tabhost with 8 tabs of the same activity(player.class). And it works :)

private void newTab(int i) {

    Intent intent = new Intent(this, Player.class);       

    TabSpec spec = mTabHost.newTabSpec("Player" + i);

    spec.setIndicator("Player " + i);

    spec.setContent(intent);

    mTabHost.addTab(spec);

} 

but the problem comes if I want to reset the scores of everyone. So I have created a Menu with onCreateOptionsMenu() with the item "Reset Scores". But I dont know how to access the Tabs开发者_C百科 to set the individual scores to '0'.

I have tried :

Player.setScores(0); // but it only change the score of the last created tab(Predictably)

any suggestions?

Thanks in advance.


In your Player Activity, you can acces your TabActivity by calling getParent(). Then you just have to call getTabHost(). This way you have full access to each sub activity of your TabActivity.

0

精彩评论

暂无评论...
验证码 换一张
取 消