Android. How to detect when ui was updated after submit list in recycler view?

890 Views Asked by At

I have implemented search contacts applications. Contact list may be very large. For implementation I used kotlin flow, RecyclerView and AsyncListDiffer. Initially, I used diff util, but after that I noticed that on some devices, lags began when searching and updating the list. I understand that this is due to the fact that the list is updated in the ui thread and because of this, ui is blocked. So I decided to use AsyncListDiffer. After that, the lags stopped. But now my list is updated with a slight delay. That is, in the search field, I enter the numbers of the contact and only after a few seconds my list is updated according to the number entered in the edit text. I use the progress bar, but how do I know when ui has updated and can I stop the progress bar?

Please, help me.

2

There are 2 best solutions below

1
On BEST ANSWER

Use ListAdapter here example usage and documentation -> https://developer.android.com/reference/androidx/recyclerview/widget/ListAdapter

after you submitList you can hide your progressbar when recyclerView is ready

   adapter.submitList(myList) {
       // TODO: HIDE THE PROGRESS BAR
   }
0
On

Hej testivanivan,

take a look at this solution: https://stackoverflow.com/a/30429439/17799032 - I think you have to build your adapter similar to this by using a SortedList which speeds up the filtering.