0

I am facing a weird issue with data binding expressions in XML.

I need to hide a view inside a recycler view item, when a certain parameter is true. I would normally do the handling in the view holder but data binding offers quick one liners in XML. So this is what I do.

android:visibility="@{restaurant.isOpen == true ? View.GONE : View.VISIBLE}"

The problem is that, sometimes, the view is still visible when isOpen==true. I have checked postman to be sure the param is correct and it is. This seems like an odd recycling issue, but why?

This view is not handled anywhere else, the view holder is empty code-wise.

Anyone had this issue before?

M'aiq the Coder
  • 762
  • 6
  • 18
  • Maybe you need two-way data binding, try @={} instead of @{} – Reyhane Farshbaf Dec 28 '20 at 09:39
  • `android:visibility="@{restaurant.isOpen? View.GONE : View.VISIBLE}"` . This should work . You need to check whether you are notifying the adapter after value change or not . – ADM Dec 28 '20 at 10:15
  • Is your root layout a `MotionLayout`? If so, take a look at [this](https://stackoverflow.com/questions/57168071/androidvisibility-changes-to-children-of-motionlayout) post – Håkon Schia Dec 28 '20 at 11:53

0 Answers0