I have an issue with my RecyclerView and ListAdapter.
Through an API, I receive items in a ascending order from older to newer.
My list is then being refreshed by calling the submitList(items) method.
However, since everything is asynchronous, after receiving the first item, the RecyclerView remains on the position of the first item received and showed. Since in the ListAdapter class there is no callback when the submitList() method completed, I cannot find a way to scroll after the updates to one of the new items that has been added.
Is there a way to intercept when ListAdapter has been updated ?
Not specific to ListAdapter, but it should work nonetheless:
Just use adapter.registerAdapterDataObserver(RecyclerView.AdapterDataObserver)
and override the relevant onItemXXX method to tell your RecyclerView to scroll to whatever position.
As an example:
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() { override fun onItemRangeInserted(positionStart: Int, itemCount: Int) { (recycler_view.layoutManager as LinearLayoutManager).scrollToPositionWithOffset(positionStart, 0) } })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With