I have a problem with my Code:
I want to make a Highscore list with Google AppEngine and it works. Google AppEngine returns a String which is parsed and filled in a Layout. The activity HighscoreListe connects to AppEngine and will get this string.
The problem with my Highscore layout in the way I wrote below is that this activity (HighscoreListe) starts multiple times when I start the TabLayout. So I get a StringIndexOutOfBoundsException.
I want to start intent2 when I change to Tab 2 and intent3 when I change to Tab3. So that the highscores will only be loaded in the 2nd or 3rd difficulty when I click on this difficulty.
public class HighscoreTabLayout extends TabActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
System.out.println(MenuMainActivity.getDifficulties());
int diffCount = -1;
System.out.println(diffCount);
TabSpec tabSpec1 = tabHost.newTabSpec(MenuMainActivity.getDifficulties()[++diffCount].getName());
// setting Title and Icon for the Tab
tabSpec1.setIndicator(MenuMainActivity.getDifficulties()[diffCount].getName());//, getResources().getDrawable(R.drawable.icon_photos_tab));
Intent intent1 = new Intent(this, HighscoreListe.class);
intent1.putExtra("name", MenuMainActivity.getDifficulties()[diffCount].getName());
tabSpec1.setContent(intent1);
System.out.println(diffCount);
TabSpec tabSpec2 = tabHost.newTabSpec(MenuMainActivity.getDifficulties()[++diffCount].getName());
tabSpec2.setIndicator(MenuMainActivity.getDifficulties()[diffCount].getName());//, getResources().getDrawable(R.drawable.icon_songs_tab));
Intent intent2 = new Intent(this, HighscoreListe.class);
intent2.putExtra("name", MenuMainActivity.getDifficulties()[diffCount].getName());
tabSpec2.setContent(intent2);
System.out.println(diffCount);
TabSpec tabSpec3 = tabHost.newTabSpec(MenuMainActivity.getDifficulties()[++diffCount].getName());
tabSpec3.setIndicator(MenuMainActivity.getDifficulties()[diffCount].getName());//, getResources().getDrawable(R.drawable.icon_videos_tab));
Intent intent3 = new Intent(this, HighscoreListe.class);
intent3.putExtra("name", MenuMainActivity.getDifficulties()[diffCount].getName());
tabSpec3.setContent(intent3);
System.out.println(diffCount);
TabSpec tabSpec4 = tabHost.newTabSpec(MenuMainActivity.getDifficulties()[++diffCount].getName());
tabSpec4.setIndicator(MenuMainActivity.getDifficulties()[diffCount].getName());//, getResources().getDrawable(R.drawable.icon_videos_tab));
Intent intent4 = new Intent(this, HighscoreListe.class);
intent4.putExtra("name", MenuMainActivity.getDifficulties()[diffCount].getName());
tabSpec4.setContent(intent4);
System.out.println(diffCount);
// Adding all TabSpec to TabHost
tabHost.addTab(tabSpec1);
tabHost.addTab(tabSpec2);
tabHost.addTab(tabSpec3);
tabHost.addTab(tabSpec4);
tabHost.setCurrentTab(1);
}
}