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.
精彩评论