Created
April 4, 2021 03:17
-
-
Save ahndwon/efc2c887198424fa5b0880a88bbb1991 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Suppress("UNCHECKED_CAST") | |
@BindingAdapter("itemsWithListAdapter") | |
fun <T, VH : RecyclerView.ViewHolder> setItemsWithListAdapter( | |
recyclerView: RecyclerView, | |
items: List<T>? | |
) { | |
(recyclerView.adapter as? ListAdapter<T, VH>)?.let { adapter -> | |
val newList = if (items == null || items.isEmpty()) null else ArrayList(items) | |
adapter.submitList(newList) | |
if (newList == null) { | |
adapter.notifyDataSetChanged() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment