Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid TabActivity how to start Intent only on TabChange
    primarykey
    data
    text
    <p>I have a problem with my Code:</p> <p>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.</p> <p>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.</p> <p>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.</p> <pre><code>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); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload