package com.ahau.againstpestinfo.adapter;

import android.content.Context;
import android.widget.ArrayAdapter;

import java.util.List;

/**
 * 注释:
 *
 * @author fanchunchun
 * @date 2018/5/4
 */

/**
 * 给下拉框的适配器
 * Created by IBM on 2016/10/25.
 */

public class simpleArrayAdapter<T> extends ArrayAdapter {
    //构造方法
    public simpleArrayAdapter(Context context, int resource, List<T>  objects) {
        super(context, resource, objects);
    }
    //复写这个方法，使返回的数据没有最后一项
    @Override
    public int getCount() {
        // don't display last item. It is used as hint.
        int count = super.getCount();
        return count > 0 ? count - 1 : count;
    }

    /*@Override
    public int getCount() {

        return list.size() - 1;
    }*/

    @Override
    public long getItemId(int arg0) {

        return arg0;
    }

 /*   @Override
    public String getItem(int position) {

        return (String) objects.get(position);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        return getCustomView(position, convertView, parent);

    };

    public View getCustomView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(
                    android.R.layout.simple_spinner_item, parent, false);
        }
        text = (TextView) convertView.findViewById(android.R.id.text1);
        if (position == getCount()) {
            text.setText("");
            text.setHint(getItem(getCount())); // "Hint to be displayed"
        } else {
            text.setText(getItem(position));
        }

        return convertView;
    }*/

}