A
A
Alexander Kolmachikhin2018-11-24 17:05:53
Java
Alexander Kolmachikhin, 2018-11-24 17:05:53

Why is data shuffled in RecyclerView?

I have a RecyclerView with a list of jobs. After clicking "execute", the following code is triggered:

listItemTask.remove(position);
    notifyItemRemoved(position);
    notifyItemRangeChanged(position, listItemTask.size());

Then 1 element is removed from the list. The data is displayed normally. I'm deleting another list item a few positions down. Still no problem. But now, having removed an element of the list higher than the previous one, there is a mixing of the already removed and some other element that still lives in the list. Moreover, not all data is mixed, which is very confusing, because if the data is already mixed up due to, obviously, false positions, an exact copy of the last deleted element should have been obtained. But this, as I described, does not happen, something remains, but something changes.
Here is my onBindViewHolder:
public void onBindViewHolder(@NonNull final ViewHolder holder, @SuppressLint("RecyclerView") int p) {
        int position = holder.getAdapterPosition();
        ItemTask task = listItemTask.get(position); 

        holder.titleTask.setText(task.getTitle() + ""); // не заменяется

        if (task.getDeadline().equals("Без дедлайна")) { // заменяется
            holder.deadlineLayout.setVisibility(View.GONE);
        } else {
            holder.deadlineTask.setText(task.getDeadline() + "");
        }

        holder.numberCoinsTask.setText(task.getRewardCoins() + ""); // не заменяется
        holder.numberProgressTask.setText(task.getRewardProgress() + ""); // не заменяется

        iconHelper = new IconHelper(task.getAttributeImproveSkill(), task.getImportance());
        holder.iconImproveSkill.setBackgroundResource(iconHelper.getBg()); // не заменяется

        if (task.getIdImproveSkill() == -1) { // заменяется
            holder.titleImproveSkill.setText("Без улучшаемого навыка");
            holder.improveSkillLayout.setVisibility(View.GONE);
            holder.iconImproveSkill.setImageResource(R.drawable.icon_standart);

        } else { // тоже заменяется
            holder.titleImproveSkill.setText(task.getTitleImproveSkill());
            holder.iconImproveSkill.setImageResource(IconHelper.iconRes[task.getIconImproveSkill()]);
            holder.pointsAttribute.setText(task.getPointsAttributeImproveSkill() + "");
            holder.iconAttribute.setImageResource(iconHelper.getIconAttribute());
            holder.pointsAttribute.setVisibility(View.VISIBLE);
            holder.iconAttribute.setVisibility(View.VISIBLE);

        }
    }

I have been looking for a solution to this problem on the net for a long time, but I have not found it. Hope there is an answer here...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question