Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8986199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:29:38+00:00 2026-06-15T21:29:38+00:00

I have an ActionBar with List Navigation mode. The problem is after selecting items

  • 0

I have an ActionBar with List Navigation mode.
The problem is after selecting items from the navigation spinner, when the screen orientation changes the navigation spinner selected index is reset to 0.

How can I preserve the selected index of the spinner during configuration changes ?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:29:39+00:00Added an answer on June 15, 2026 at 9:29 pm

    You should override onSaveInstanceState and save selected navigation list position to bundle.
    Don’t forget to restore position in onCreate.

    Look at example below:

    public class MainActivity
    {
    
        private static final String CURRENT_FRAGMENT_TAG = "fragmentPosition";
    
        @Inject @Named("navigationFragments")
        private Provider<? extends Fragment>[] fragmentProviders;
    
        @Override
        protected void onCreate(Bundle bundle)
        {
            super.onCreate(bundle);
    
            final ActionBar actionBar = getSupportActionBar();
            actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
            actionBar.setListNavigationCallbacks(ArrayAdapter.createFromResource(
                this, R.array.navigation_menu, android.R.layout.simple_list_item_1), new ActionBar.OnNavigationListener()
            {
                @Override
                public boolean onNavigationItemSelected(int itemPosition, long itemId)
                {
                    final String fragmentTag = "fragment-" + itemPosition;
    
                    // to prevent fragment re-selection and loosing early saved state
                    if (getSupportFragmentManager().findFragmentByTag(fragmentTag) != null)
                    {
                        return true;
                    }
    
                    final Fragment fragment = fragmentProviders[itemPosition].get();
                    getSupportFragmentManager().beginTransaction().
                        replace(android.R.id.content, fragment, fragmentTag).
                        commit();
                    return true;
                }
            });
            actionBar.setSelectedNavigationItem(bundle != null
                ? bundle.getInt(CURRENT_FRAGMENT_TAG)
                : 0);
        }
    
        @Override
        protected void onSaveInstanceState(Bundle outState)
        {
            super.onSaveInstanceState(outState);
            outState.putInt(CURRENT_FRAGMENT_TAG, getSupportActionBar().getSelectedNavigationIndex());
        }
    
        /*
    
            Additional stuff here
    
         */
    
    }
    

    Provider<? extends Fragment>[] fragmentProviders is a list of factory method objects which creates new fragment.
    Replace getSupportActionBar() to getActionBar() and getSupportFragmentManager() to getFragmentManager() if you don’t use actionbarsherlock

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Android 4.1 ActionBar provides a useful navigation mode as a list or tab.
In my main activity, I have an ActionBar with navigation tabs and action items.
I have an actionBar with multiple items, I would like to change the colour
I have a screen which uses ViewPager + actionbar Sherlock tabs. I have a
I have an activity which loads a data list from the server using loader
I'm trying to fix the issue with restarting activity on orientation changes. I have
I am using ActionBarSherlock and have an ActionBar with navigation tabs in it. I
I have a actionbar with a custom layout, but this show me the icon
I have this application where I implement the ActionBar Fragment interface. Underlying the interface,
I have an app that uses the ActionBar with tabs in combination with Fragments.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.