kotlin android中Recyclerview的适配器类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了kotlin android中Recyclerview的适配器类相关的知识,希望对你有一定的参考价值。
This the base code for creating adapter class which is used for filling recyclerview in android.This snippet is written in kotlin but it is same to the java version
class ClassName(val list:ArrayList<Type of your list>):RecyclerView.Adapter<ClassName.ViewHolder>() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ClassName.ViewHolder { val v = LayoutInflater.from(parent.context).inflate(R.layout.item_layout, parent, false) return ViewHolder(v) } override fun getItemCount(): Int { return list.size } override fun onBindViewHolder(holder: ClassName.ViewHolder, position: Int) { holder.bindItems(list[position]) } class ViewHolder(itemview: View):RecyclerView.ViewHolder(itemview) { fun bindItems(t: type of your list){ } } }
以上是关于kotlin android中Recyclerview的适配器类的主要内容,如果未能解决你的问题,请参考以下文章
Android@Kotlin 在Android studio 中配置Kotlin
Android@Kotlin 在Android studio 中配置Kotlin
Android@Kotlin 在Android studio 中配置Kotlin