onBindViewHolder在调用diffResult.dispatchUpdatesTo(this)之后未调用

问题描述 投票:0回答:1

我正在通过以下方式将我的数据设置为回收者视图:

public void setData(List<Notification> newNotifications) {
        DiffUtil.DiffResult diffResult = getDiffBetweenNewAndOldList(newNotifications);
        diffResult.dispatchUpdatesTo(this);
        this.notificationList.clear();
        this.notificationList.addAll(newNotifications);
    }

现在我面临的问题是,当我获取新的其他数据时(例如,旧列表的大小为10,而下一页面的数据为下一个10值),那时我的onBindViewHolder称为:

@Override
    public void onBindViewHolder(@NonNull NotificationViewHolder holder, int position) {
        holder.bindView(notificationList.get(position));
        if (position == notificationList.size() - 1) {
            EventBus.getDefault().post(new UpdateEvent.GetNotificationList(GetNotificationDataFrom.ON_LOAD_NEXT_PAGE, notificationList.get(position).getNotification_time()));
        }
    }

当我刷新数据并再次获得列表的第一页时,则不会调用onBindViewHolder。当我使用notifyDataSetChanged()时,没有这样的问题。我该如何解决这个问题?

android android-recyclerview notifydatasetchanged android-diffutils
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.