Is there any Method to reload recyclerview items without blinking as i am loading data from API

119 views Asked by At

In my Adapter class (AnyListAdapter.kt) i am loading data using API but everytime i perform an action on particular item my whole recyclerview list clears and then data again load from API. What i have to do is:

  • As soon as i perform an action on item in recyclerview whole list reloads and items get updated without blinking or fluctuation.
  • i Dont want to clear my list and load it again i want to reload it withou showing.

Can anyone help in this i am stuck at this not able to find any soultion.

onButtonClickListner{
ClassPerformActionOnItem()
}

fun classPerformActionOnItem(){
//Performing my action on item
//image visiblity,text visibility etc.
item.clear()  
CallAPI()
}

the above code snippet is example of what i am doing. is there any way to reload item without clearing and again showing as it is giving blinking effect.

1

There are 1 answers

2
Alexander Hoffmann On

Don't call item.clear() inside classPerformActionOnItem. Wait for the API call to finish and once it is really done, replace the items.

This should improve your situation but it will probably not completely solve the problem.

To completely get rid of the problem, convert your RecyclerView Adapter to a ListAdapter.

A ListAdapter is a speciall kind of RecyclerView.Adapter which checks the difference between one set of data and another. It can automatically animate the changes in a RecyclerView by animating items in, out and move them around.

Check out this guide for the implementation.