I have a recyclerview that contains a list of pre-defined UI layout elements. In the pre-defined UI layout, there is an icon that is visible if the item is a type of project. If it's not that type, it is not visible. When the user enters selection mode, I set a custom variable in the adapter to hide this icon on all items, however it is not working.
I've tried using DiffUtil callback for updating the contents (i.e. returning false for contentsIsSame when it's the one with visible icon on status change), and I see it flicker, but for only one row, and it reverts.
I've tried using notifydatasetchanged, also invalidateAll, neither works.
I looked on internet for anything that is similar to my issue, but was unable to find any solutions that worked.
In the pre-defined UI layout XML for each row:
<variable
name="isSelecting"
type="boolean"/>
Then in the visibility binding (omitted other attributes):
<ImageView
app:visibleGone="@{project.isIconVisible && !isSelecting}"/>
In RecyclerView.Adapter class code that creates the list:
listItemBinding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_project_list, parent, false);
When the selection button is pressed, this is called:
public void setIsSelecting(boolean isSelecting){
listItemBinding.setIsSelecting(isSelecting);
This is where I tried different methods, such as listItemBinding.invalidateAll().
If I manually set isSelecting to true or false, before the list is populated, it correctly shows/hides the icons. It's just not updating when it's changed.