Android lazy data binding possible?

Viewed 1968

One of the coolest features of the Android data binding support is that it also generates fields for View with IDs set. This tidies up the codebase as no field or findViewById() calls are necessary.

But the problem is that the binding instance can only be retrieved via the bind() call which tends to schedule binding. This is bad when the data is being received asynchronously and commonly the NullPointerException gets thrown.

Can the binding instance with View fields be retrieved minus the actual data binding process?

Stack-trace:

java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
         at com.app.android.databinding.ActivityRestaurantDetailsBinding.executeBindings(ActivityRestaurantDetailsBinding.java:381)
         at android.databinding.ViewDataBinding.executePendingBindings(ViewDataBinding.java:350)
         at android.databinding.ViewDataBinding$6.run(ViewDataBinding.java:167)
         at android.databinding.ViewDataBinding$5.onViewAttachedToWindow(ViewDataBinding.java:137)
         at android.view.View.dispatchAttachedToWindow(View.java:14525)
2 Answers

Got the same problem with java.lang.Boolean. Solved by using primitive boolean type instead.

<variable
    name="var"
    type="boolean" />
Related