Devlight / NavigationTabStrip

Navigation tab strip with smooth interaction.
Apache License 2.0
2.24k stars 313 forks source link

setOnPageChangeListener #20

Open juanlabrador opened 8 years ago

juanlabrador commented 8 years ago

When I change of fragment, always return position 0.

mViewPager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int position) {
                switch (position) {
                    case 0:
                        return mHistoryFragment;
                    case 1:
                        return  mPostFragment;
                    default:
                        return null;
                }
            }

            @Override
            public int getCount() {
                return 2;
            }
        });

        mViewPager.setPageMargin(8); // TODO Convert 'px' to 'dp'
        mViewPager.setPageMarginDrawable(R.color.accent);

        mTabsAction.setViewPager(mViewPager);
        mTabsAction.setTitles(getString(R.string.button_new_history), getString(R.string.button_new_post));
        //mTabsAction.setTabIndex(0, true);
        mTabsAction.setStripColor(getResources().getColor(R.color.accent));
        mTabsAction.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                validateButton();
                switch (position) {
                    case 0:
                        TAB = HISTORY;
                        validateDraft(Constants.HISTORY);
                        break;
                    case 1:
                        TAB = POST;
                        validateDraft(Constants.POST);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        mTabsAction.setOnTabStripSelectedIndexListener(new NavigationTabStrip.OnTabStripSelectedIndexListener() {
            @Override
            public void onStartTabSelected(String title, int index) {
                validateButton();
                switch (index) {
                    case 0:
                        TAB = HISTORY;
                        validateDraft(Constants.HISTORY);
                        break;
                    case 1:
                        TAB = POST;
                        validateDraft(Constants.POST);
                        break;
                }
            }

            @Override
            public void onEndTabSelected(String title, int index) {

            }
        });

thanks

GIGAMOLE commented 8 years ago

Hello. Thanks for issue.This is seems like imbossinillity.

sunyz2016 commented 8 years ago

I have encountered this problem.

hackware1993 commented 8 years ago

hava a try,https://github.com/hackware1993/MagicIndicator

uzumakinaruto123 commented 7 years ago

Any workaround for this?