package xn.hxp.ui.adapter


import android.content.Context
import android.util.TypedValue
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import xn.hxp.R


class CustomSpinnerAdapter(private val ct: Context, private val dataList: List<String>) : BaseAdapter() {

    override fun getCount(): Int {
        return dataList.size
    }

    override fun getItem(position: Int): Any {
        return dataList[position]
    }

    override fun getItemId(position: Int): Long {
        return position.toLong()
    }

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        var view = convertView
        val viewHolder: ViewHolder

        if (view == null) {
            view = LayoutInflater.from(ct).inflate(R.layout.custom_spinner_item, parent, false)
            viewHolder = ViewHolder()
            viewHolder.textView = view.findViewById(R.id.spinnerItemText)

            view.tag = viewHolder
        } else {
            viewHolder = view.tag as ViewHolder
        }
        viewHolder.textView.text = "${dataList[position]}层"

        return view!!
    }

    override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup?): View? {
        val view = super.getDropDownView(position, convertView, parent) as TextView
        view.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f) // 设置字体大小为12sp
        return view
    }

    private class ViewHolder {
        lateinit var textView: TextView
    }
}