Recycler view not scrolling to the top after adding new item at the top, as changes to the list adapter has not yet occurred

后端 未结 5 1483
无人及你
无人及你 2021-02-07 06:37

I am getting the new list with new item at the start in my live data and then using its data to update the adapter

viewModel.myLiveData.observe { this, Observer          


        
5条回答
  •  星月不相逢
    2021-02-07 06:56

    Another way to Solve this Problem is wrapping the Recyclerview inside the Nested ScrollView.

     
               
    
    

    Then inside your Activity or Fragment.

    viewModel.myLiveData.observe { this, Observer { myList -> 
        adapter.submitList(myList) 
        nestedScrollView.scrollTo(0,0);
    }
    

提交回复
热议问题