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

Time:05-17

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.

CodePudding user response:

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
   }

CodePudding user response:

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.

  • Related