【发布时间】:2012-11-21 12:50:21
【问题描述】:
我的代码有问题:
我想用 Google AppEngine 制作一个高分列表,它可以工作。 Google AppEngine 返回一个经过解析并填充到布局中的字符串。 活动 HighscoreListe 连接到 AppEngine 并将获取此字符串。
我在下面编写的 Highscore 布局的问题是,当我启动 TabLayout 时,此活动 (HighscoreListe) 会启动多次。所以我得到一个 StringIndexOutOfBoundsException。
我想在切换到 Tab 2 时启动 intent2,在切换到 Tab3 时启动 intent3。 这样当我点击这个难度时,只会在第二或第三难度加载高分。
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);
}
}
【问题讨论】:
标签: android android-intent tabactivity tabview