0
votes

I implemented view pager in my activity like :

class MainActivity extends FragmentActivity implements
        ActionBar.TabListener {

    private ViewPager viewPager;
    private TabsPagerAdapter mAdapter;
    private ActionBar actionBar;
    // Tab titles
    private String[] tabs = { "FIRST", "SECOND", "THIRD" };

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

        // Initilization
        viewPager = (ViewPager) findViewById(R.id.pager);
        mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

        viewPager.setAdapter(mAdapter);
        getActionBar().setHomeButtonEnabled(false);
        getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);   
        // Adding Tabs
        for (String tab_name : tabs) {
            getActionBar().addTab(getActionBar().newTab().setText(tab_name)
                    .setTabListener(this));
        } 

but when I swipe between tabs it never call the oncreateview of THIRD fragment but it actually call the oncreateview of THIRD fragment when I swipe to the SECOND fragment (From first to Second) and the oncreate view of second fragment get call along with the first fragment.

I don't understand what's wrong with the flow.

1

1 Answers

0
votes

There is nothing wrong with this. when you swipe to new page in viewpager, it automatically loads the two neighbor fragments of current visible fragment. why? because of having better UX.

Can I prevent it from doing that?

No.

Can I extend it to load more neighbor fragments?

yes, setOffscreenPageLimit