I've made a list which gets items from a Room-database using LiveData
. This liveData<List>
is then bound to a recyclerView
, using a BindingAdapter
.
The lists adapter is listAdapter
, not `RecyclerView.Adapter.
I need help holding onto the scroll-state or somehow returning to the scroll-index I was at before the recyclerView
reloaded:
//In ViewModel
val movieList = moviesRepository.movies
..
//in Repo
val movies: LiveData<List<Movie>> =
Transformations.map(database.movieDao.getMovies()) {
it.asDomainModel()
}
Every time the DB updates, the recyclerView
shoots back up to the top.
And here's the bindingAdapter
for the RecyclerView
and the list.
@BindingAdapter("listData")
fun bindRecyclerView(recyclerView: RecyclerView, data: List<Movie>?) {
val adapter = recyclerView.adapter as MovieListAdapter
//Log.d("listData binding", "${data}")
adapter.submitList(data)
}
I think I need to use something like recyclerView.smoothScrollToPosition(la.getItemCount());
after the update has occured, but I don't know how to automatically call it when the update has occured