recyclerview adapter in kotlin code example
Example 1: recyclerview onCreateViewHolder kotlin
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val v: View = LayoutInflater.from(parent?.context)
.inflate(R.layout.custom_view, parent, false)
return ViewHolder(
v
)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder?.name?.text = list.get(position).description
}
Example 2: recyclerview adapter in kotlin
class CustomAdapter(private val dataSet: Array<String>) :
RecyclerView.Adapter<CustomAdapter.ViewHolder>() {
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
}
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
}
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
}
override fun getItemCount() {
}
}