I am using a RecyclerView to show some attributes from my class. One of the attributes in that class is a price. An EditView where you can enter a number for your money. A TextView which shows a summed up price from multiselect below.
I have enabled multiselect successfully and summed up the price from each item using a tracker to show in the TextView. I also used my own SelectionPredicate class to prohibit selecting another item if the remaining money is not enough to select an item with a higher price.
Now I also want to grey out all items which you can no longer click because of the remaining money < price.
I found this RecyclerView: Changing background color of a Textview on each List Item which basically is what I need and I successfully got that working with one problem:
I used the logic provided in the above link to do a setBackgroundRessource to color the to expensive items which works, but only on items not in sight. So if I scroll down my RecyclerView and new items come into view which are to expensive, that have the new background and if I scroll back to my starting point of view the items to expensive there are now also coloured differently.
What I am missing is how to trigger the changed background also for the rows which are currently on the screen and to expensive.
I tried putting notifyDataSetChanged() into the tracker.addObserver onSelectionChange method, but that triggers an endless loop until the app crashes as the next background change triggers that again I guess.
So I am looking for a way to do the recolouring once after each select or deselect and not only on the items outside of the screen, but on the onces I can currently see as well.
So in a nutshell, I need the changes apply on the current visible items of my RecyclerView as well, not just the ones out of sight.