Android TabActivity如何仅在TabChange上启动Intent
我的代码有问题: 我想用谷歌AppEngine制作一个高分列表,它可以工作。Google AppEngine返回一个字符串,该字符串被解析并填充到布局中。 活动HighscoreListe连接到AppEngine并将获取此字符串 我在下面写的Highscore布局的问题是,当我开始TabLayout时,这个活动(HighscoreListe)会启动多次。所以我有一个StringIndexOutOfBoundsException 我想在切换到选项卡2时启动intent2,切换到选项卡3时启动intent3。 因此,当我点击这个难度时,高分只会在第二或第三个难度中加载Android TabActivity如何仅在TabChange上启动Intent,android,android-intent,tabactivity,tabview,Android,Android Intent,Tabactivity,Tabview,我的代码有问题: 我想用谷歌AppEngine制作一个高分列表,它可以工作。Google AppEngine返回一个字符串,该字符串被解析并填充到布局中。 活动HighscoreListe连接到AppEngine并将获取此字符串 我在下面写的Highscore布局的问题是,当我开始TabLayout时,这个活动(HighscoreListe)会启动多次。所以我有一个StringIndexOutOfBoundsException 我想在切换到选项卡2时启动intent2,切换到选项卡3时启动int
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);
}
}如果我明白你的意思,你应该在tabhost的tab chage listner上设置: `setOnTabChangedListener(新的ontabchangedListener(){
@Override
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
}
})`