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

voidaddOnRebindCallback(OnRebindCallback listener)

Add a listener to be called when reevaluating dirty fields.

voidexecutePendingBindings()

Evaluates the pending bindings, updating any Views that have expressions bound to modified variables.

ViewgetRoot()

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

abstract booleanhasPendingBindings()

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

abstract voidinvalidateAll()

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

voidremoveOnRebindCallback(OnRebindCallback listener)

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

voidsetLifecycleOwner(LifecycleOwner lifecycleOwner)

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

abstract booleansetVariable(int variableId, Object value)

Set a value value in the Binding class.

voidunbind()

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
listenerOnRebindCallback: 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
Viewthe 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
booleantrue 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
listenerOnRebindCallback: 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
lifecycleOwnerLifecycleOwner: 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
variableIdint: the BR id of the variable to be set. For example, if the variable is x, then variableId will be BR.x.

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

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

unbind

void unbind ()

Removes binding listeners to expression variables.