package com.iforce2d.balloontrackerv2;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.util.Log;

public class MyPagerAdapter extends FragmentStatePagerAdapter {
    int mNumOfTabs;

    public Fragment tab1 = null;
    public Fragment tab2 = null;
    public Fragment tab3 = null;
    public Fragment tab4 = null;

    public MyPagerAdapter(FragmentManager fm, int NumOfTabs) {
        super(fm);
        this.mNumOfTabs = NumOfTabs;
    }

    @Override
    public Fragment getItem(int position) {

        switch (position) {
            case 0:
                if ( tab1 != null ) return tab1;
                tab1 = new TabFragment1();
                return tab1;
            case 1:
                if ( tab2 != null ) return tab2;
                tab2 = new TabFragment2();
                return tab2;
            case 2:
                if ( tab3 != null ) return tab3;
                tab3 = new TabFragment3();
                return tab3;
            case 3:
                if ( tab4 != null ) return tab4;
                tab4 = new TabFragment4();
                return tab4;
            default:
                return null;
        }
    }

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