RecyclerView not showing anything after updating Adapter data

后端 未结 2 1922
谎友^
谎友^ 2020-12-21 20:47

guys i need help with this matter i have been going through my code for a couple of days to figure whats going wrong but i couldn\'t figure it out. I have a fragment with a

2条回答
  •  粉色の甜心
    2020-12-21 21:43

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

    public void setMyAdapterData(ArrayList 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 newData) {
        this.data.clear();
        this.data.addAll(newData);
        this.notifyDataSetChanged();
    }
    

提交回复
热议问题