|
| 1 | +package com.xxmassdeveloper.mpchartexample.notimportant |
| 2 | + |
| 3 | +import android.annotation.SuppressLint |
| 4 | +import android.content.Context |
| 5 | +import android.graphics.Typeface |
| 6 | +import android.view.LayoutInflater |
| 7 | +import android.view.View |
| 8 | +import android.view.ViewGroup |
| 9 | +import android.widget.ArrayAdapter |
| 10 | +import android.widget.TextView |
| 11 | +import com.xxmassdeveloper.mpchartexample.R |
| 12 | + |
| 13 | +internal class MenuAdapter(context: Context, objects: List<ContentItem<*>?>?) : ArrayAdapter<ContentItem<*>?>(context, 0, objects!!) { |
| 14 | + private val mTypeFaceLight: Typeface = Typeface.createFromAsset(context.assets, "OpenSans-Light.ttf") |
| 15 | + private val mTypeFaceRegular: Typeface = Typeface.createFromAsset(context.assets, "OpenSans-Regular.ttf") |
| 16 | + |
| 17 | + @SuppressLint("InflateParams") |
| 18 | + override fun getView(position: Int, convertView: View?, parent: ViewGroup): View { |
| 19 | + val c = getItem(position) |
| 20 | + |
| 21 | + val holder = ViewHolder() |
| 22 | + |
| 23 | + val inflatedView = if (c != null && c.isSection) { |
| 24 | + LayoutInflater.from(context).inflate(R.layout.list_item_section, null) |
| 25 | + } else { |
| 26 | + LayoutInflater.from(context).inflate(R.layout.list_item, null) |
| 27 | + } |
| 28 | + |
| 29 | + holder.tvName = inflatedView.findViewById(R.id.tvName) |
| 30 | + holder.tvDesc = inflatedView.findViewById(R.id.tvDesc) |
| 31 | + |
| 32 | + inflatedView.tag = holder |
| 33 | + |
| 34 | + if (c != null && c.isSection) |
| 35 | + holder.tvName?.setTypeface(mTypeFaceRegular) |
| 36 | + else |
| 37 | + holder.tvName?.setTypeface(mTypeFaceLight) |
| 38 | + holder.tvDesc?.setTypeface(mTypeFaceLight) |
| 39 | + |
| 40 | + holder.tvName?.text = c?.name |
| 41 | + holder.tvDesc?.text = c?.desc |
| 42 | + |
| 43 | + return inflatedView |
| 44 | + } |
| 45 | + |
| 46 | + private inner class ViewHolder { |
| 47 | + var tvName: TextView? = null |
| 48 | + var tvDesc: TextView? = null |
| 49 | + } |
| 50 | +} |
0 commit comments