RecyclerView notifyDataSetChanged scrolls to top position

前端 未结 8 2091
北海茫月
北海茫月 2020-12-11 00:11

when calling notifyDataSetChanged on RecyclerView it doesn\'t retain the scroll position and scrolls to top, is there any solution to retain it\'s

8条回答
  •  清歌不尽
    2020-12-11 00:59

    Not sure if this solves your problem but I was having the same issue and it was because I was calling setAdapter after notify. So, not calling setAdapter after notify solved the problem.

    mAdapter.notifyItemRangeInserted(mAdapter.getItemCount(), list.size() - 1);
    recyclerView.setAdapter(); // remove this line. 
    //Do this only when you're setting the data for the first time or when adapter is null. 
    

提交回复
热议问题