I'm new in kotlin programming language,how to implement a list view in kotlin using base adapter in android. any one can help me.
How can we implement base adapter with kotlin in android? [closed]
Asked Answered
it's very similar to android only.. –
Pathogenesis
Write the code in java and convert it into Kotlin using the tools provided by the Android Studio –
Wolford
Can you help me with code. –
Shirleeshirleen
ok @SamuelRobert –
Shirleeshirleen
What problem have you encountered when you try to write it in Kotlin? –
Mariehamn
check this code
public class ListViewActivity() : AppCompatActivity() {
override fun onCreate(savedState: Bundle?) {
super.onCreate(savedState)
setContentView(R.layout.activity_list_view)
val lv = findViewById(R.id.list) as ListView
lv.adapter = ListExampleAdapter(this)
}
private class ListExampleAdapter(context: Context) : BaseAdapter() {
internal var sList = arrayOf("Sunday", "Monday")
private val mInflator: LayoutInflater
init {
this.mInflator = LayoutInflater.from(context)
}
override fun getCount(): Int {
return sList.size
}
override fun getItem(position: Int): Any {
return sList[position]
}
override fun getItemId(position: Int): Long {
return position.toLong()
}
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View? {
val view: View?
val vh: ListRowHolder
if (convertView == null) {
view = this.mInflator.inflate(R.layout.list_row, parent, false)
vh = ListRowHolder(view)
view.tag = vh
} else {
view = convertView
vh = view.tag as ListRowHolder
}
vh.label.text = sList[position]
return view
}
}
private class ListRowHolder(row: View?) {
public val label: TextView
init {
this.label = row?.findViewById(R.id.label) as TextView
}
}
Thanks @Sk -Sandip Kalola –
Shirleeshirleen
need to implement ThemedSpinnerAdapter also –
Profusion
© 2022 - 2024 — McMap. All rights reserved.