Hey all, I'm stuck trying to show/hide a layout us...
# android-databinding
t
Hey all, I'm stuck trying to show/hide a layout using databinding, I'm sure I'm missing something really obvious and could benefit from your help if you have time 🙂 I'm doing this is my Fragment for a RecyclerView:
Copy code
binding = DataBindingUtil.inflate(inflater, R.layout.list_empty, null, false)
binding.setVariable(BR.items, adapter.items)
Then everytime my
items: ObservableArrayList
changes I do
binding.notifyPropertyChanged(BR.items)
My
list_empty.xml
is as follows:
Copy code
<layout xmlns:android="http://schemas.android.com/apk/res/android">

    <data>
        <import type="android.view.View"/>
        <variable name="items" type="android.databinding.ObservableArrayList"/>
    </data>

    <LinearLayout
            [...]
            android:visibility="@{items.size() == 0 ? View.VISIBLE : View.GONE}">
            
            [...]

    </LinearLayout>

</layout>
I also tried to notify changes with:
Copy code
binding.invalidateAll()
binding.executePendingBindings()
binding.notifyChange()
But no success.. 😞 The app compiles and runs with no issues, but the empty view is always showing. What am I missing? Thanks for helping 🙂