Cannot call notifyItemInserted() from RecyclerView.OnScrollListener

前端 未结 4 1524
清歌不尽
清歌不尽 2021-01-31 14:52

Recently I upgrade my recyclerview-v7:23 to recyclerview-v7:24.2.0. My applicaton has an endless scroll list. The error message points to the line

4条回答
  •  半阙折子戏
    2021-01-31 15:12

    1. The issue is not with new version of Recyclerview.

    2 & 3. You cannot change item while it is setting (with calling onBindViewHolder). In that case you have to call notifyItemInserted at the end of current loop by calling Handler.post()

    Handler handler = new Handler();
    
        final Runnable r = new Runnable() {
            public void run() {
                articleAdapter.notifyItemInserted(allArticles.size() - 1);
            }
        };
    
        handler.post(r);
    

    I hope, it will solve your problem.

提交回复
热议问题