package com.rdiot.yx485.adapter;

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.rdiot.yx485.bean.EditDeviceReplyBean;

import java.util.List;

public class DeviceSpinnerAdapter extends BaseAdapter {
    private final Context context;
    private final List<EditDeviceReplyBean.DataBean.DeviceBean> items;

    public DeviceSpinnerAdapter(Context context, List<EditDeviceReplyBean.DataBean.DeviceBean> items) {
        this.context = context;
        this.items = items;
    }

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

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(android.R.layout.simple_spinner_dropdown_item, parent, false);
        }

        TextView text = convertView.findViewById(android.R.id.text1);
        text.setText(items.get(position).name);

        return convertView;
    }
}
