package com.genlot.ninglottery.widget.CustomSpinnerDropDown;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.genlot.ninglottery.R;

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

/**
 * 类描述：
 * 创建人：songjing
 * 创建时间：2019/6/26 14:03
 * 修改人：songjing
 * 修改时间：2019/6/26 14:03
 * 修改备注：下拉框
 */
public class AbstractSpinerAdapter<T> extends BaseAdapter {

    public interface IOnItemSelectListener {
        void onItemClick(View view, int pos);
    }


    private Context mContext;
    private List<T> mObjects = new ArrayList<T>();

    private LayoutInflater mInflater;

    public AbstractSpinerAdapter(Context context) {
        init(context);
    }

    public void refreshData(List<T> objects) {
        mObjects = objects;
    }

    private void init(Context context) {
        mContext = context;
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }


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

    @Override
    public Object getItem(int pos) {
        return mObjects.get(pos);
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int pos, View convertView, ViewGroup arg2) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_textview_type, null);
            viewHolder = new ViewHolder();
            viewHolder.mTextView = convertView.findViewById(R.id.tv_name_type);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }


        Object item = getItem(pos);
        viewHolder.mTextView.setText(item.toString());

        return convertView;
    }

    public static class ViewHolder {
        public TextView mTextView;
    }
}