2

I am setting my data to recycler view by this :

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

Now the issue I am facing is that when I am getting new additional data(eg old list is for size 10 and I get the data fro the next page for next 10 values), at that time my onBindViewHolder is called :

@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()));
        }
    }

When I refresh my data and get the 1st page again of the list, then onBindViewHolder is not called. There is no such issue when I use notifyDataSetChanged(). How can I solve this problem?

Parth Anjaria
  • 3,961
  • 3
  • 30
  • 62

1 Answers1

0

You can try:

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