package com.taikor.investment.adapter;

import android.graphics.Color;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.TextView;

import java.util.List;

/** 最佳组合页面文字的轮播图适配器
 * Created by Any on 2017/3/29.
 */
public class TextAdapter extends PagerAdapter {
    
    private List<TextView> mList;

    public void setData(List<TextView> list){
        this.mList = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return arg0 == arg1;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
       
        //取模计算出当前的是第几个页面
        int i = position % mList.size();
        // 预防负值
        position = Math.abs(i);
        
        final TextView textView = mList.get(position);
        textView.setTextColor(Color.parseColor("#FFFFFF"));
        textView.setTextSize(14);
        textView.setLineSpacing(10,1);//行间距
        textView.setBackgroundColor(Color.parseColor("#aa5E4328"));
        ViewParent parent = textView.getParent();
        // remove掉View之前已经加到一个父控件中，否则报异常
        if (parent != null) {
            ViewGroup group = (ViewGroup) parent;
            group.removeView(textView);
        }
        container.addView(textView);

        return textView;
    }
}

