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

前端 未结 26 2520
借酒劲吻你
借酒劲吻你 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:54

    I got this to work using Cocorico suggestion in a previous answer (https://stackoverflow.com/a/26927186/3660638) but there's a catch: since I'm using a SortedList, using notifyDataSetChanged() everytime there's a change in data (add, remove, etc) makes you lose the item animations that you get with notifyItemXXXXX(position), so what I ended up doing was using it only when I change the data in batch, like:

    public void addAll(SortedList items) {
        movieList.beginBatchedUpdates();
        for (int i = 0; i < items.size(); i++) {
            movieList.add(items.get(i));
        }
        movieList.endBatchedUpdates();
        notifyDataSetChanged();
    }  
    

提交回复
热议问题