繁体   English   中英

notifyDataSetChanged()没有调用onBindViewHolder

[英]notifyDataSetChanged() is not calling onBindViewHolder

当我调用notifyDataSetChanged()时,它不会调用我的onBindViewHolder,我也不知道为什么这样做,我正在使用自定义布局,并且不知道是否与此有关。

有人有什么想法吗? 这是代码,我在适配器内调用数据集更改时使用的代码是和平的。

public void updateFriendsCheckinData(HashMap<Integer, List<LiveCheckin>>  updatedCheckinMap){
        this.friendCheckinMap = updatedCheckinMap;
        notifyDataSetChanged();
    }

尝试这个:

public void updateFriendsCheckinData(HashMap<Integer, List<LiveCheckin>> updatedCheckinMap) {
    // here we are clearing existing data in the HashMap
    friendCheckinMap.clear();

    friendCheckinMap = updatedCheckinMap;
    notifyDataSetChanged();
}

然后在您的getItemCount()方法中,我们有:

@Override
public int getItemCount() {
    // if you are using the data in the list retrieved from the hashmap, then here return the size of the list instead.
    return friendCheckinMap.size();
 }

希望这可以帮助。

您必须在onClick事件而不是OnBindviewHolder中调用notifydatasetchanged。

如果调用OnBindviewHolder,则可能由于recyclerview填充视图而崩溃。

这是示例代码

 @Override
public void onRecyclerViewItemClick(@NonNull View view, @NonNull AndroidVersion calendarDTO, int position) {

    Toast.makeText(getContext(),String.valueOf(position), Toast.LENGTH_SHORT).show();

        adapter.notifyDataSetChanged();

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM