Skip to content

Instantly share code, notes, and snippets.

@kozmi55
Created Aug 16, 2021
Embed
What would you like to do?
@BindingAdapter("itemViewModels")
fun bindItemViewModels(recyclerView: RecyclerView, itemViewModels: List<ItemViewModel>?) {
val adapter = getOrCreateAdapter(recyclerView)
adapter.updateItems(itemViewModels)
}
private fun getOrCreateAdapter(recyclerView: RecyclerView): BindableRecyclerViewAdapter {
return if (recyclerView.adapter != null && recyclerView.adapter is BindableRecyclerViewAdapter) {
recyclerView.adapter as BindableRecyclerViewAdapter
} else {
val bindableRecyclerAdapter = BindableRecyclerViewAdapter()
recyclerView.adapter = bindableRecyclerAdapter
bindableRecyclerAdapter
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment