Skip to content

Instantly share code, notes, and snippets.

View TayfunCesur's full-sized avatar
💭
The quieter you become the more you are able to hear

Tayfun Cesur TayfunCesur

💭
The quieter you become the more you are able to hear
View GitHub Profile
@sockeqwe
sockeqwe / AdapterDelegateDslExample.kt
Created July 22, 2019 08:19
AdapterDelegates Kotlin DSL
/**
* Let's say we want to display a list of Animals in a RecyclerView.
* The list can contain items of type Dog, Cat and Snake.
*/
// AdapterDelegate for Dog.
fun dogAdapterDelegate(picasso : Picasso) = adapterDelegate<Dog, Animal>(R.layout.item_dog){ // Generics Types means this AdapterDelegate is used if item is instanceof Dog (whole list is List<Anmial>)
// this block is run once in onCreateViewHolder. Think of it as an intializer for a ViewHolder.
val name = findViewById(R.id.name)
val image = findViewById(R.id.image)