package com.yidianling.dynamic.trendsHome;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

/**
 * Created by Jim on 2017/9/22 0022.
 */

public class TrendsHomeVpAdapter extends FragmentPagerAdapter {

    public final static int dataSize=3;
    private Fragment[] mFragments;
    private String[] titles = new String[]{
            "推荐", "最新", "关注", "待回答", "我回答的"
    };

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

    public TrendsHomeVpAdapter(FragmentManager fm, Fragment[] fragments) {
        super(fm);
        mFragments = fragments;
    }

    public void setDatas(Fragment[] fragments){
        mFragments=fragments;
    }

    @Override
    public Fragment getItem(int position) {
        if (mFragments.length > 0) {
            return mFragments[position];
        }
        return null;
    }

    @Override
    public int getCount() {
        return mFragments!=null&&mFragments.length > 0 ? mFragments.length : 0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mFragments.length>0){
            return titles[position];
        }
        return super.getPageTitle(position);
    }
}
