I'm using data binding and I'm running into an issue where a view property that I bind to is not being populated immediately after the layout is inflated and the view model is set for the binding class.
In the containing Fragment I use BindingUtil to inflate the bound layout in the Fragment's onCreateView(). I then immediately set the binding variable which is my view model.
However, when I debug right after setting the binding's view model the layout has nulls for some of the view's properties I've bound to the view model. If I wait a fraction of a second the properties will be set via binding as expected.
Thus, when does the actual binding of the view's properties occur? I assumed it occurred as soon as the view model was set to the binding class. This must be wrong...
Can someone help me with a sound way to debug this issue?
Per the Data Binding documentation:
When a variable or observable changes, the binding will be scheduled to change before the next frame. There are times, however, when binding must be executed immediately. To force execution, use the executePendingBindings() method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With