Skip to content

Commit 3514afa

Browse files
committed
Kotlin MenuAdapter
1 parent 56d4425 commit 3514afa

File tree

3 files changed

+51
-72
lines changed

3 files changed

+51
-72
lines changed

MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/notimportant/MainActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MainActivity : AppCompatActivity(), OnItemClickListener {
2424

2525
// initialize the utilities
2626
Utils.init(this)
27-
val adapter = MyAdapter(this, menuItems)
27+
val adapter = MenuAdapter(this, menuItems)
2828
val lv = findViewById<ListView>(R.id.listViewMain)
2929
lv.adapter = adapter
3030
lv.onItemClickListener = this
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

MPChartExample/src/main/java/com/xxmassdeveloper/mpchartexample/notimportant/MyAdapter.java

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)