/ Published in: Other
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
This snippet is written in kotlin but it is same to the java version
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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){ } } }