我正在通过以下方式将我的数据设置为回收者视图:
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()时,没有这样的问题。我该如何解决这个问题?