0

I have an activity which contains a viewpager to swipe across 4 fragments. I'm also using ActionBar.NAVIGATION_MODE_TABS to display the tabs name and allow navigating by pressing on on the tab as well as swiping

    public void onCreate(Bundle savedInstanceState) {
...
        this.viewPager = (ViewPager) findViewById(R.id.viewPager);
        this.viewPagerAdapter = new MyViewPagerAdapter(this, getSupportFragmentManager());
        this.viewPager.setAdapter(this.viewPagerAdapter);
        this.viewPager.setCurrentItem(0);

        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
            // Create a tab listener that is called when the user changes tabs.
            final TabListener tabListener = new TabListener() {

                @Override
                public void onTabReselected(Tab arg0, FragmentTransaction arg1) {

                }

                @Override
                public void onTabSelected(Tab tab, FragmentTransaction arg1) {
                        viewPager.setCurrentItem(tab.getPosition());
                    }
                }

                @Override
                public void onTabUnselected(Tab arg0, FragmentTransaction arg1) {
                }
            };


// add the tabs

            this.viewPager.setOnPageChangeListener(
                    new ViewPager.SimpleOnPageChangeListener() {
                        @Override
                        public void onPageSelected(int position) {
                                // When swiping between pages, select the corresponding tab.
                                actionBar.setSelectedNavigationItem(position);
                        }
                    });

This works fine, but when the device is in landscape orientation, the tabs are displayed as an action spinner, then the spinner content doesn't refresh anymore when swiping in the viewpager even though onPageSelected() is called with the correct position

Any idea how to fix this ?

Thanks

user1026605
  • 1,633
  • 4
  • 22
  • 58
  • possible duplicate of [How to stop ActionBar Tab navigation to display as a spinner when it gets too long?](http://stackoverflow.com/questions/13828659/how-to-stop-actionbar-tab-navigation-to-display-as-a-spinner-when-it-gets-too-lo) – bummi May 16 '15 at 17:21

1 Answers1

0

For now I will use the following workaround, but I'm still interested in finding a real solution. The workaround is to force the display of the tabs even in landscape by setting the navigation mode after the tabs have been added as seen here

Community
  • 1
  • 1
user1026605
  • 1,633
  • 4
  • 22
  • 58