Android RecyclerView : notifyDataSetChanged() IllegalStateException

前端 未结 22 1864
天涯浪人
天涯浪人 2020-11-28 02:57

I\'m trying to update the items of a recycleview using notifyDataSetChanged().

This is my onBindViewHolder() method in the recycleview adapter.

@Over         


        
22条回答
  •  独厮守ぢ
    2020-11-28 03:41

    protected void postAndNotifyAdapter(final Handler handler, final RecyclerView recyclerView, final RecyclerView.Adapter adapter) {
            handler.post(new Runnable() {
                @Override
                public void run() {
                    if (!recyclerView.isComputingLayout()) {
                        adapter.notifyDataSetChanged();
                    } else {
                        postAndNotifyAdapter(handler, recyclerView, adapter);
                    }
                }
            });
        }
    

提交回复
热议问题