How to remove horizontal recyclerview(child) inside the recyclerview(parent) scroll to first position when notifyitemchange?

38 views Asked by At

I am using multiple view type inside the recyclerview. In which one of the view type is recyclerview of linear layoutmanager with horizontal orientation. I loaded all view type inside the parent recyclerview. When I change the some item in horizonatal recyclerview item of position 10 and update by adapter?.notifyItemChanged(10), the horizonatal recyclerview jump to first position 0. And it creates a bad user experience.

Also I used android:descendantFocusability="blocksDescendants" and setHasFixedSize(true) in parent and child Recyclerview not does not works. Is there is any way to solve my problem. And also attached image for reference enter image description here

Here position 1 is horizonal recyclerview

1

There are 1 answers

0
Rajan Kali On

You could save the RecyclerView's layout instance and restore post notifying adapter, this will restore layout manager properties like scroll position

val savedInstance = recyclerView.layoutManager?.onSaveInstanceState()
adapter?.notifyItemChanged(10)
recyclerView.layoutManager?.onRestoreInstanceState(savedInstance)