notifyDataSetChange not working on RecyclerView [duplicate]

旧时模样 提交于 2019-11-30 10:53:35
wmora

My issue was that I was not notifying the change on the main thread, therefore the change was not visible right away. It is the same issue pointed out here.

I was trying to update RecycleView with notifyDataSetChanged() method in response to com.google.common.eventbus.Subscribe.

Like @wmora mentioned the problem was that the notify method was not called in the main UI thread.

I resolved it with AndroidAnnotations' @UiThread

@UiThread
protected void dataSetChanged() {
    notifyDataSetChanged();
}

which is equivalent to:

 final Adapter adapter = this;
 new Handler(Looper.getMainLooper()).post(new Runnable() {
    @Override
    public void run() {
       adapter.notifyDataSetChanged();
    }
 });

note: just separate new Handler into class private field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!