I am looking for a practical example for both the cases that what to use when? I have seen similar threads but they only tell this "when binding must be executed immediately" but there is no real time example for any case where you have to force the binding to be executed. So please if anyone can explain with any example that when to use it and when its not that required!
executePendingBindings() Evaluates the pending bindings, updating any Views that have expressions bound to modified variables. View. getRoot() Returns the outermost View in the layout file associated with the Binding.
Layout Binding expressions Expressions in the XML layout files are assigned to a value of the attribute properties using the “ @{} " syntax. We just need to use the basic syntax @{} in an assignment expression.
inflate. Inflates a binding layout and returns the newly-created binding for that layout. Use this version only if layoutId is unknown in advance. Otherwise, use the generated Binding's inflate method to ensure type-safe inflation.
The case when you should use executePendingBindings()
is (but there could be more):
Every time the binding update could cause a View to change its size and postponing the calculation in the next frame could cause the measurement to read wrong values.
In case of a RecyclerView
, this happens if:
viewType
s with different sizes (different XML)RecyclerView
will measure the row size after the onBindViewHolder
has completed. If based on the data you set in this method the height of the row changes, the measurement could not take into account the extra or reduced space occupied by your new content if you do not call executePendingBindings()
.
Forcing the binding to update data synchronously and not in the next frame keeps you safe from wrong row size measurement (and potentially missing content)
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