To remove the highlighting background color from the last selected RecyclerView item when I return from my details activity, I tried this in onResume()
:
mAdapter.notifyItemChanged(mAdapter.selectedPos);
mAdapter.selectedPos = RecyclerView.NO_POSITION;
and this in onBindViewHolder()
:
viewHolder.itemView.setSelected(selectedPos == position);
onBindViewHolder()
is always called after onResume()
so selectedPos == position
gives the correct result but I don't understand why it's not called earlier.
Why don't I have to save selectedPos
in a temp variable and call notifyItemChanged(temp)
after the change of selectedPos
?
Thanks in advance.