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 8970847
In Process

The Archive Base Latest Questions

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

I have a screen which uses ViewPager + actionbar Sherlock tabs. I have a

  • 0

I have a screen which uses ViewPager + actionbar Sherlock tabs. I have a setOnPageChangeListener set on the pager and it does the following:

@Override
public void onPageSelected(final int position) {
    actionBar.setSelectedNavigationItem(position);
}

This works just fine in portrait mode and even in landscape if I only have few tabs and all the tabs are displayed. However if I add few more tabs in landscape, these collapse into a single drop-down widget. When I page through the ViewPager the setSelectedNavigationItem method is executed but now it has no effect on the drop-down selection: it stays at the last selected value. Which is really bad since user is missing a visual clue: tab may say “One” but user is already on page #6.

Is there a way to programmatically change which tab to display based on the position?

P.S. I know why this happens:
Here’s code from com.android.internal.app.ActionBarImpl:

public void setSelectedNavigationItem(int position) {
    switch (mActionView.getNavigationMode()) {
    case NAVIGATION_MODE_TABS:
        selectTab(mTabs.get(position));
        break;
    case NAVIGATION_MODE_LIST:
        mActionView.setDropdownSelectedPosition(position);
        break;
    default:
        throw new IllegalStateException(
                "setSelectedNavigationIndex not valid for current navigation mode");
    }
}

And when I step through that I can see that the navigation mode is still NAVIGATION_MODE_TABS though tabs are displayed as list. Now – my knee jerk reaction is to put code into onConfigurationChanged to set navigation mode appropriately but shouldn’t this happen automatically?

P.P.S. And there’s Android bug filed for it already that contains the patch

  • 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-15T17:48:30+00:00Added an answer on June 15, 2026 at 5:48 pm

    Base on the Android bug I’m referencing in the question (see P.P.S.) here’s workaround that indeed works. Just add it to your pager

    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
         {
            @Override
            public void onPageSelected(int position)
            {
               actionBar.getTabAt(position).select();
               ViewParent root = findViewById(android.R.id.content).getParent();
               findAndUpdateSpinner(root, position);
            }
    
            /**
             * Searches the view hierarchy excluding the content view 
             * for a possible Spinner in the ActionBar. 
             * 
             * @param root The parent of the content view
             * @param position The position that should be selected
             * @return if the spinner was found and adjusted
             */
            private boolean findAndUpdateSpinner(Object root, int position)
            {
               if (root instanceof android.widget.Spinner)
               {
                  // Found the Spinner
                  Spinner spinner = (Spinner) root;
                  spinner.setSelection(position);
                  return true;
               }
               else if (root instanceof ViewGroup)
               {
                  ViewGroup group = (ViewGroup) root;
                  if (group.getId() != android.R.id.content)
                  {
                     // Found a container that isn't the container holding our screen layout
                     for (int i = 0; i < group.getChildCount(); i++)
                     {
                        if (findAndUpdateSpinner(group.getChildAt(i), position))
                        {
                           // Found and done searching the View tree
                           return true;
                        }
                     }
                  }
               }
               // Nothing found
               return false;
            }
         });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using 960.gs, I have a page which is a login screen which uses a
I'm using Codeigniter/PyroCMS which uses ion_auth. I have my session stuff set for two
I have created a master page in asp.net which uses the following css to
I have the following JTable which uses a table model: http://s17.postimage.org/7zfh3l4lr/Screen_Shot_2012_03_10_at_15_11_31.png Instead of using,
I have created an app which uses Application Settings and user defaults following the
I have application which uses fragments. Depending on screen size and orientation I'm displaying
I have a site, which uses paging. I use the following plugin for tooltips:
I have an app which uses an osmdroid mapactivity. Every time the screen orientation
I have search screen which has 10 fields and involves around 5 to 6
I will have a screen in which there will be 11 images one below

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.