سؤال

i have a viewpager and i have four tabs. i have these codes (just like google's tutorial) in my adapter:

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

    @Override
    public void onPageScrollStateChanged(int state) {
    }

    @Override
    public void onTabSelected(Tab tab, FragmentTransaction ft) {
        Object tag = tab.getTag();
        for (int i=0; i<mTabs.size(); i++) {
            if (mTabs.get(i) == tag) {
                mViewPager.setCurrentItem(i);
            }
        }
    }

when i select a tab, the app crashes. it seems like setCurrentItem and setSelectedNavigationItem are calling each other and it crashes the app. am i doing something wrong?

هل كانت مفيدة؟

المحلول

Maybe you your onTabSelected(.....), try doing this :

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

Works for me. You can try it.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top