Return to Snippet

Revision: 80873
at April 5, 2020 16:21 by m3000

Initial Title
Adapter class for Recyclerview in kotlin android

Initial Description
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

Initial Code
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) {
    class ViewHolder(itemview: View):RecyclerView.ViewHolder(itemview)
        fun bindItems(t: type of your list){

Initial Tags

Initial Language

Initial URL