package com.daya.live_teaching.ui.adapter;

import android.view.ViewGroup;

import java.util.List;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;

public class FixPagerAdapter extends FragmentStatePagerAdapter {

    // Tabs上显示的title
    private String[]       titles;
    // Tabs对应的fragment集合
    private List<Fragment> fragments;

    public FixPagerAdapter(FragmentManager fm, String[] titles, List<Fragment> fragments) {
        super(fm);
        this.titles = titles;
        this.fragments = fragments;
    }


    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments == null ? 0 : fragments.size();
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {

        Fragment fragment = null;
        try {
            fragment = (Fragment) super.instantiateItem(container, position);
        } catch (Exception e) {
        }

        return fragment;
    }


    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }
}