ViewDataBinding

public abstract class ViewDataBinding
extends BaseObservable

java.lang.Object
   ↳ android.databinding.BaseObservable
     ↳ android.databinding.ViewDataBinding


Base class for generated data binding classes. If possible, the generated binding should be instantiated using one of its generated static bind or inflate methods. If the specific binding is unknown, bind(View) or inflate(LayoutInflater, int, ViewGroup, boolean) should be used.

Summary

Public methods

void addOnRebindCallback(OnRebindCallback listener)

Add a listener to be called when reevaluating dirty fields.

void 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.

abstract boolean hasPendingBindings()

Returns whether the UI needs to be refresh to represent the current data.

abstract void invalidateAll()

Invalidates all binding expressions and requests a new rebind to refresh UI.

void removeOnRebindCallback(OnRebindCallback listener)

Removes a listener that was added in addOnRebindCallback(OnRebindCallback).

void setLifecycleOwner(LifecycleOwner lifecycleOwner)

Sets the LifecycleOwner that should be used for observing changes of LiveData in this binding.

abstract boolean setVariable(int variableId, Object value)

Set a value value in the Binding class.

void unbind()

Removes binding listeners to expression variables.

Inherited methods

From class android.databinding.BaseObservable
From class java.lang.Object
From interface android.databinding.Observable

Public methods

addOnRebindCallback

void addOnRebindCallback (OnRebindCallback listener)

Add a listener to be called when reevaluating dirty fields. This also allows automatic updates to be halted, but does not stop explicit calls to executePendingBindings().

Parameters
listener OnRebindCallback: The listener to add.

executePendingBindings

void executePendingBindings ()

Evaluates the pending bindings, updating any Views that have expressions bound to modified variables. This must be run on the UI thread.

getRoot

View getRoot ()

Returns the outermost View in the layout file associated with the Binding. If this binding is for a merge layout file, this will return the first root in the merge tag.

Returns
View the outermost View in the layout file associated with the Binding.

hasPendingBindings

boolean hasPendingBindings ()

Returns whether the UI needs to be refresh to represent the current data.

Returns
boolean true if any field has changed and the binding should be evaluated.

invalidateAll

void invalidateAll ()

Invalidates all binding expressions and requests a new rebind to refresh UI.

removeOnRebindCallback

void removeOnRebindCallback (OnRebindCallback listener)

Removes a listener that was added in addOnRebindCallback(OnRebindCallback).

Parameters
listener OnRebindCallback: The listener to remove.

setLifecycleOwner

void setLifecycleOwner (LifecycleOwner lifecycleOwner)

Sets the LifecycleOwner that should be used for observing changes of LiveData in this binding. If a LiveData is in one of the binding expressions and no LifecycleOwner is set, the LiveData will not be observed and updates to it will not be propagated to the UI.

Parameters
lifecycleOwner LifecycleOwner: The LifecycleOwner that should be used for observing changes of LiveData in this binding.

setVariable

boolean setVariable (int variableId, 
                Object value)

Set a value value in the Binding class.

Typically, the developer will be able to call the subclass's set method directly. For example, if there is a variable x in the Binding, a setX method will be generated. However, there are times when the specific subclass of ViewDataBinding is unknown, so the generated method cannot be discovered without reflection. The setVariable call allows the values of variables to be set without reflection.

Parameters
variableId int: the BR id of the variable to be set. For example, if the variable is x, then variableId will be BR.x.

value Object: The new value of the variable to be set.

Returns
boolean true if the variable is declared or used in the binding or false otherwise.

unbind

void unbind ()

Removes binding listeners to expression variables.