简体   繁体   中英

ActionBarSherlock TabPageIndicator with ViewPager.OnPageChangeListener - tab is stuck

I am running the example code provided with ABS (SampleTabsDefault). I added the OnPageChangeListener as shown below, now the TabPageIndicator is always stuck on the first tab even though the tab content changes. Am I doing something wrong?

@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.simple_tabs);

    mAdapter = new GoogleMusicAdapter(getSupportFragmentManager());

    mPager = (ViewPager)findViewById(R.id.pager);
    mPager.setAdapter(mAdapter);

    mIndicator = (TabPageIndicator)findViewById(R.id.indicator);
    mIndicator.setViewPager(mPager);

    ViewPager.OnPageChangeListener changeListener = new ViewPager.OnPageChangeListener() {

       @Override
       public void onPageScrolled(int i, float v, int i1) {}

       @Override
       public void onPageSelected(int i) {}

       @Override
       public void onPageScrollStateChanged(int i) {}
    };

    mPager.setOnPageChangeListener(changeListener);
    mIndicator.setOnPageChangeListener(changeListener);
}

The issue was that setting a change listener was overriding the code responsible for switching tabs. I could have subclassed the ABS class, but elected to switch to a TitlePageIndicator which does not have any issues with setting the listener..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM