package com.xypower.common;

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

import java.util.List;

public class CompactSpinnerAdapter extends BaseAdapter implements SpinnerAdapter {

    private Context mContext ;
    private String[] mList;
    private int mLayoutViewId;

    public CompactSpinnerAdapter(Context context, int arrayResId, int layoutViewId){
        mContext = context;
        mList = context.getResources().getStringArray(arrayResId);
        mLayoutViewId = layoutViewId;
    }

    @Override
    public int getCount() {
        return mList.length;
    }

    @Override
    public Object getItem(int position) {
        return mList[position];
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = LayoutInflater.from(mContext);
        View view = layoutInflater.inflate(mLayoutViewId, null);
        if(view != null)
        {
            if (view.getClass().isInstance(TextView.class)) {
                TextView textView = (TextView) view;
                textView.setText(mList[position]);
            }
        }
        return view;
    }


}