Skip to content
Akshay Kondekar edited this page May 18, 2020 · 1 revision

Welcome to the BlogOneKotlinRecyclerview wiki!

Android Recyclerview using Kotlin.

This code is for Beginners who want to learn kotlin from basic. Here you can learn how to reduce code and make it error free. Also Adding animation to recyclerview with recycler item click listener using higher-order function and let scoping function to set listener only if itemAction has been set.

`

private var itemAction: ((Animal) -> Unit)? = null

fun clickedItemAction(action: (Animal) -> Unit) {
    this.itemAction = action
}

inner class AnimalViewHolder(itemView : View) : RecyclerView.ViewHolder(itemView) {
    fun bind(animal: Animal) {
        
        itemAction?.let {
            itemView.setOnClickListener { it(animal) }
        }
    }
}

`

Clone this wiki locally