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 1473
无人及你
无人及你 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:54

    You can also use

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

提交回复
热议问题