package com.kfzs.duanduan.adp;

import android.content.Context;
import android.support.annotation.StringRes;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

/**
 * @ Created by Dlg
 * @ <p>TiTle:  AdpSearchViewPager</p>
 * @ <p>Description:</p>
 * @ date:  2017/6/22 16:17
 * @ QQ:    315096953
 */

public class AdpSearchViewPager extends PagerAdapter {

    private Context mContext;

    private List<Integer> mListTitles = new ArrayList<>();
    private List<View> mListItem = new ArrayList<>();

    public AdpSearchViewPager(Context context) {
        this.mContext = context;
    }

    public void addView(View view, @StringRes int resId) {
        mListItem.add(view);
        mListTitles.add(resId);
    }


    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        container.addView(mListItem.get(position));
        return mListItem.get(position);
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView(mListItem.get(position));
    }

    @Override
    public int getItemPosition(Object object) {
        return super.getItemPosition(object);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return mContext.getString(mListTitles.get(position));
    }

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

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);
    }
}
