Skip to content

Instantly share code, notes, and snippets.

@kozmi55
Created Aug 16, 2021
Embed
What would you like to do?
interface ItemViewModel {
...
val bindableProperties: Map<Int, Any>
}
class CarAdViewModel(val make: String, val model: String, val price: String) : ItemViewModel {
...
override val bindableProperties: Map<Int, Any> = mapOf(
BR.make to make,
BR.model to model
)
}
class BindableViewHolder(private val binding: ViewDataBinding) : RecyclerView.ViewHolder(binding.root) {
fun bind(itemViewModel: ItemViewModel) {
itemViewModel.bindableProperties.entries.forEach {
binding.setVariable(it.key, it.value)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment