RecyclerView not showing anything after updating Adapter data

微笑、不失礼 提交于 2019-11-29 18:15:32

I did call notifyDataSetChanged but this was not the issue after alooooooooot of testing and Logging the problem was with setAdapterData method where i just passed the data reference from the loader to the adapter but this didn't work and i had to clone the arraylist instead of just passing the reference which sounds strange to me and i still don't understand why I had to do that if you can take a look at the setAdapterData method in MyGridAdapter class and tell me what do you think

Try invoking notifyDataSetChanged() when you modify your adapter data:

public void setMyAdapterData(ArrayList<HashMap> data){
    this.data = data;
    dataChanged = true;
    notifyDataSetChanged();
    if (listener != null){
        listener.onDataSetChanged(dataChanged);
    }
}

I see that you attempt to do this in the callback on your listener, but perhaps it is null and therefore never firing the notification?

[COMMENT] When I want to replace the entire collection of data in my adapter I often write a method similar to this:

public void setData(List<MyData> newData) {
    this.data.clear();
    this.data.addAll(newData);
    this.notifyDataSetChanged();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!