Question

Here my code:

    Tab tab = actionBar
            .newTab()
            .setText(R.string.friends)
            .setTabListener(
                    new TabListener<FriendsFragment>(this, "friends_list",
                            FriendsFragment.class));
    actionBar.addTab(tab);

    tab = actionBar
            .newTab()
            .setText(R.string.home)
            .setTabListener(
                    new TabListener<UserHomeFragment>(this, "user_home",
                            UserHomeFragment.class));
    actionBar.addTab(tab);

    tab = actionBar
            .newTab()
            .setText(R.string.highscores)
            .setTabListener(
                    new TabListener<HighscoresFragment>(this, "highscores",
                            HighscoresFragment.class));
    actionBar.addTab(tab);

How can i set the "UserHome" as first tab displayed/selected? I want it in the middle like now. So when my "TabActivity" start it will be like this: Friends - Home - Highscores

Was it helpful?

Solution

There are a few options, the easiest with your current implementation be to just set it as the selected tab when adding the tab to the action bar with ActionBar#addTab(Tab tab, boolean setSelected).

Alternatively you could set the selection with ActionBar#setSelectedNavigationItem(int position).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top