Inconsistency detected in RecyclerView, How to change contents of RecyclerView while scrolling

前端 未结 26 2463
借酒劲吻你
借酒劲吻你 2020-12-01 00:59

I\'m using RecyclerView to display name of the items. My row contains single TextView. Item names are stored in List mItemList<

26条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 01:51

    Avoid notifyDatasetHasChanged() and do the following:

    public void setItems(ArrayList
    newArticles) { //get the current items int currentSize = articles.size(); //remove the current items articles.clear(); //add all the new items articles.addAll(newArticles); //tell the recycler view that all the old items are gone notifyItemRangeRemoved(0, currentSize); //tell the recycler view how many new items we added notifyItemRangeInserted(0, articles.size()); }

提交回复
热议问题