0

I am new to android fragments. I have 3 tabs, first one is for authentication and next 2 are used for some other info which requires a user authentication in first tab to visit these tabs. I am not getting this how can I stop navigating to other fragments until user authentication is performed. I have sample code:

public class SiteSectionsPagerAdapter extends FragmentPagerAdapter {

    public SiteSectionsPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int position) {
        switch (position) {
            case 0:
                return authFragment;
            case 1:
                return siteInfoFragment;
            case 2:
                return userInfoFragment;
        }
        return null;
    }

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

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                return "Auth";
            case 1:
                return "Site info";
            case 2:
                return "user info";
        }
        return null;
    }

}

In main activity class OnCreate method have like this:

mViewPager = (ViewPager) findViewById(R.id.siteContainer);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        final ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
            @Override
            public void onPageSelected(int position) {
                actionBar.setSelectedNavigationItem(position);
            }
        });


 @Override
    public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) {
        mViewPager.setCurrentItem(tab.getPosition());

    }

Start of application is showing Authfragment first. When user authenticates in this fragment, I have a application in which I am adding a status flag isUserAuthenticate=true;

I am confused on which step I should check that if isUserAuthenticate is true then let him go for next fragment otherwise stop and remain on auth fragment. Can someone give me hint or example.

Anuja Kothekar
  • 2,537
  • 2
  • 15
  • 28
user565
  • 871
  • 1
  • 22
  • 47

1 Answers1

0

You have to make non-swipeable ViewPager:

Here is your reference:How do disable paging by swiping with finger in ViewPager but still be able to swipe programmatically?

Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66