package com.zhilin.patrol.adapter;

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

import java.util.List;

/**
 * fragment适配器
 */
public class FragmentAdapter extends FragmentPagerAdapter {

    private List<Fragment> mListFragment;

    private List<String> mListTitle;

    private Context mContext;

    public FragmentAdapter(FragmentManager fm, Context context, List<Fragment> listFragment) {
        super(fm);
        this.mContext = context;
        this.mListFragment = listFragment;
    }


    public FragmentAdapter(FragmentManager fm, Context context, List<Fragment> listFragment, List<String> listTitle) {
        super(fm);
        this.mContext = context;
        this.mListFragment = listFragment;
        this.mListTitle = listTitle;
    }

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

    @Override
    public int getCount() {
        return mListFragment.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        if (mListTitle == null) {
            return super.getPageTitle(position);
        }
        return mListTitle.get(position);
    }
}
