0

コードに問題があります:

Google AppEngine でハイスコア リストを作成したいのですが、うまくいきます。Google AppEngine は、解析されてレイアウトに入力される文字列を返します。アクティビティ HighscoreListe は AppEngine に接続し、この文字列を取得します。

以下に書いたように、私の Highscore レイアウトの問題は、TabLayout を開始すると、このアクティビティ (HighscoreListe) が複数回開始されることです。したがって、StringIndexOutOfBoundsException が発生します。

Tab2に切り替えたらintent2、Tab3に切り替えたらintent3を起動したい。この難易度をクリックすると、ハイスコアが 2 番目または 3 番目の難易度でのみ読み込まれるようにします。

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);


}

}

4

1 に答える 1

0

私があなたのポイントを得た場合、あなたはタブホストのタブチェイスリストナーに設定する必要があります:

`mTabHost.setOnTabChangedListener(new OnTabChangeListener(){

        @Override
        public void onTabChanged(String tabId) {
            // TODO Auto-generated method stub

        }
    })`
于 2012-11-21T12:59:10.913 に答える