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 1476
无人及你
无人及你 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:45

    Thank you everyone for response. But the only work that did worked for me was to place a 1 second delay after executing submitList. Even though not appropriate one, But works for the following reason:

    adapter.submitList() will always take the same execution time (within milliseconds)

    I just called

    Handler().postDelayed ({
      recycler.scrollToPosition(0)
    }, 1000)
    

提交回复
热议问题