Skip to content

Instantly share code, notes, and snippets.


nitrico/LastAdapterWithListeners.kt Secret

Last active Apr 1, 2017
What would you like to do?
val tweetType = Type<ItemTweetBinding>(R.layout.item_tweet)
// all these methods are optional:
.onCreate { println("Created #${it.adapterPosition}: ${it.binding.item}") }
.onBind { println("Bound #${it.adapterPosition}: ${it.binding.item}") }
.onRecycle { println("Recycled #${it.adapterPosition}: ${it.binding.item}") }
.onClick { toast("Clicked #${it.adapterPosition}: ${it.binding.item}") }
.onLongClick { toast("Long-clicked #${it.adapterPosition}: ${it.binding.item}") }
LastAdapter(items, BR.item)
// you can also define the callbacks directly in the map call:
.map<User, ItemUserBinding>(R.layout.item_user) {
// again, all the methods are optional:
onCreate { println("Created #${it.adapterPosition}: ${it.binding.item}") }
onBind { println("Bound #${it.adapterPosition}: ${it.binding.item}") }
onRecycle { println("Recycled #${it.adapterPosition}: ${it.binding.item}") }
onClick { toast("Clicked #${it.adapterPosition}: ${it.binding.item}") }
onLongClick { toast("Long-clicked #${it.adapterPosition}: ${it.binding.item}") }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.