package com.rdiot.yx485.adapter;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;

import com.rdiot.yx485.bean.HomeResultBean;
import com.rdiot.yx485.home.HomeFragment;

import java.util.List;

public class HomePagerAdapter extends FragmentStateAdapter {
    private List<HomeResultBean.HomeInfo> mlist;

    public HomePagerAdapter(@NonNull FragmentActivity fm, List<HomeResultBean.HomeInfo> list) {
        super(fm);
        this.mlist = list;
    }

    @NonNull
    @Override
    public Fragment createFragment(int position) {
        // 根据位置创建不同的Fragment
        return HomeFragment.newInstance(mlist.get(position));
    }

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