Is there a way to update (automatically) the RecyclerView
when a list is populated with data?
I created a simple app (here is the repository for the app).
In HomeFragment
there is a RecyclerView
and a button to refresh the data.
The app works fine as long as I have the following code in HomeFragment
to update the adapter whenever the StateFlow
list gets data.
private fun setupObservers() {
lifecycleScope.launchWhenStarted {
vm.state.collect() {
if (it.list.isNotEmpty()) {
todoAdapter.data = it.list
} else {
todoAdapter.data = emptyList()
}
}
}
}
My question is, is there a away for the RecyclerView
to update, without having to observe (or collect) the changes of the list of the StateFlow
?