package com.ifavine.pay.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.ifavine.pay.utils.BaseUtil;

/**
 * Created by Administrator on 2018/10/18.
 */

public class SpinnerAdapter extends ArrayAdapter<Object> {
    Context context;
    Object[] items = new Object[]{};

    public SpinnerAdapter(final Context context,
                          final int textViewResourceId, final Object[] objects) {
        super(context, textViewResourceId, objects);
        this.items = objects;
        this.context = context;
    }

    public void setData(final Object[] objects) {
        this.items = objects;
    }

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

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

        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(
                    android.R.layout.simple_spinner_item, parent, false);
        }

        TextView tv = (TextView) convertView
                .findViewById(android.R.id.text1);
        tv.setPadding(10, 10, 10, 10);
        tv.setText((String) items[position]);
        tv.setGravity(Gravity.CENTER);
        tv.setTextColor(Color.BLACK);
        tv.setTextSize(BaseUtil.Dp2Px(context, 23));
        return convertView;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            LayoutInflater inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(
                    android.R.layout.simple_spinner_item, parent, false);
        }
        TextView tv = (TextView) convertView
                .findViewById(android.R.id.text1);
        tv.setPadding(10, 10, 10, 10);
        tv.setText((String) items[position]);
        tv.setGravity(Gravity.CENTER);
        tv.setTextColor(Color.BLACK);
        tv.setTextSize(BaseUtil.Dp2Px(context, 20));
        return convertView;
    }
}