# DataBindingUtil

Summary:[Methods](https://developer.android.com/reference/android/databinding/DataBindingUtil#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/databinding/DataBindingUtil#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/databinding/DataBindingUtil#)  

# DataBindingUtil

`
public


class
DataBindingUtil
`  
`

extends `[Object](http://developer.android.com/reference/java/lang/Object.html)`


``


`

|---|-------------------------------------|
| [java.lang.Object](http://developer.android.com/reference/java/lang/Object.html) ||
| ↳ | android.databinding.DataBindingUtil |

<br />

*** ** * ** ***

Utility class to create[ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)from layouts.

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                       ### Public methods                                                                                                                                                                                                                                                                                                                                                                                        ||
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` static <T extends `[ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)`> T` | ` `[bind](https://developer.android.com/reference/android/databinding/DataBindingUtil#bind(android.view.View))`(`[View](http://developer.android.com/reference/android/view/View.html)` root) ` Returns the binding for the given layout root or creates a binding if one does not exist.                                                                                                                                                                                                                                                                                                                                                                             |
| ` static <T extends `[ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)`> T` | ` `[bind](https://developer.android.com/reference/android/databinding/DataBindingUtil#bind(android.view.View, android.databinding.DataBindingComponent))`(`[View](http://developer.android.com/reference/android/view/View.html)` root, `[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)` bindingComponent) ` Returns the binding for the given layout root or creates a binding if one does not exist.                                                                                                                                                                                                      |
| ` static `[String](http://developer.android.com/reference/java/lang/String.html)                                         | ` `[convertBrIdToString](https://developer.android.com/reference/android/databinding/DataBindingUtil#convertBrIdToString(int))`(int id) ` Converts the given BR id to its string representation which might be useful for logging purposes.                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ` static <T extends `[ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)`> T` | ` `[findBinding](https://developer.android.com/reference/android/databinding/DataBindingUtil#findBinding(android.view.View))`(`[View](http://developer.android.com/reference/android/view/View.html)` view) ` Retrieves the binding responsible for the given View.                                                                                                                                                                                                                                                                                                                                                                                                   |
| ` static <T extends `[ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)`> T` | ` `[getBinding](https://developer.android.com/reference/android/databinding/DataBindingUtil#getBinding(android.view.View))`(`[View](http://developer.android.com/reference/android/view/View.html)` view) ` Retrieves the binding responsible for the given View layout root.                                                                                                                                                                                                                                                                                                                                                                                         |
| ` static `[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)       | ` `[getDefaultComponent](https://developer.android.com/reference/android/databinding/DataBindingUtil#getDefaultComponent())`() ` Returns the default[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)used in data binding.                                                                                                                                                                                                                                                                                                                                                                                     |
| ` static <T extends `[ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)`> T` | ` `[inflate](https://developer.android.com/reference/android/databinding/DataBindingUtil#inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean, android.databinding.DataBindingComponent))`(`[LayoutInflater](http://developer.android.com/reference/android/view/LayoutInflater.html)` inflater, int layoutId, `[ViewGroup](http://developer.android.com/reference/android/view/ViewGroup.html)` parent, boolean attachToParent, `[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)` bindingComponent) ` Inflates a binding layout and returns the newly-created binding for that layout. |
| ` static <T extends `[ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)`> T` | ` `[inflate](https://developer.android.com/reference/android/databinding/DataBindingUtil#inflate(android.view.LayoutInflater, int, android.view.ViewGroup, boolean))`(`[LayoutInflater](http://developer.android.com/reference/android/view/LayoutInflater.html)` inflater, int layoutId, `[ViewGroup](http://developer.android.com/reference/android/view/ViewGroup.html)` parent, boolean attachToParent) ` Inflates a binding layout and returns the newly-created binding for that layout.                                                                                                                                                                        |
| ` static <T extends `[ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)`> T` | ` `[setContentView](https://developer.android.com/reference/android/databinding/DataBindingUtil#setContentView(android.app.Activity, int))`(`[Activity](http://developer.android.com/reference/android/app/Activity.html)` activity, int layoutId) ` Set the Activity's content view to the given layout and return the associated binding.                                                                                                                                                                                                                                                                                                                           |
| ` static <T extends `[ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)`> T` | ` `[setContentView](https://developer.android.com/reference/android/databinding/DataBindingUtil#setContentView(android.app.Activity, int, android.databinding.DataBindingComponent))`(`[Activity](http://developer.android.com/reference/android/app/Activity.html)` activity, int layoutId, `[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)` bindingComponent) ` Set the Activity's content view to the given layout and return the associated binding.                                                                                                                                                    |
| ` static void`                                                                                                           | ` `[setDefaultComponent](https://developer.android.com/reference/android/databinding/DataBindingUtil#setDefaultComponent(android.databinding.DataBindingComponent))`(`[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)` bindingComponent) ` Set the default[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)to use for data binding.                                                                                                                                                                                                                   |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/databinding/DataBindingUtil#)From class` `[java.lang.Object](http://developer.android.com/reference/java/lang/Object.html)` ` |------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------| | ` `[Object](http://developer.android.com/reference/java/lang/Object.html)          | ` clone() `                                                                               | | ` boolean`                                                                         | ` equals(`[Object](http://developer.android.com/reference/java/lang/Object.html)` arg0) ` | | ` void`                                                                            | ` finalize() `                                                                            | | ` final `[Class](http://developer.android.com/reference/java/lang/Class.html)`<?>` | ` getClass() `                                                                            | | ` int`                                                                             | ` hashCode() `                                                                            | | ` final void`                                                                      | ` notify() `                                                                              | | ` final void`                                                                      | ` notifyAll() `                                                                           | | ` `[String](http://developer.android.com/reference/java/lang/String.html)          | ` toString() `                                                                            | | ` final void`                                                                      | ` wait(long arg0, int arg1) `                                                             | | ` final void`                                                                      | ` wait(long arg0) `                                                                       | | ` final void`                                                                      | ` wait() `                                                                                | ||

## Public methods

### bind

```
T bind (View root)
```

Returns the binding for the given layout root or creates a binding if one does not exist. This uses the DataBindingComponent set in[setDefaultComponent(DataBindingComponent)](https://developer.android.com/reference/android/databinding/DataBindingUtil#setDefaultComponent(android.databinding.DataBindingComponent)).

Prefer using the generated Binding's`bind`method to ensure type-safe inflation when it is known that`root`has not yet been bound.

<br />

|                              Parameters                              ||
|--------|--------------------------------------------------------------|
| `root` | `View`: The root View of the inflated binding layout. <br /> |

|                                                     Returns                                                      ||
|-----|-------------------------------------------------------------------------------------------------------------|
| `T` | A ViewDataBinding for the given root View. If one already exists, the existing one will be returned. <br /> |

|                                                                            Throws                                                                             ||
|------------------------------------------------------------------------------------------------------------|---------------------------------------------------|
| [IllegalArgumentException](http://developer.android.com/reference/java/lang/IllegalArgumentException.html) | when root is not from an inflated binding layout. |

**See also:**

- [getBinding(View)](https://developer.android.com/reference/android/databinding/DataBindingUtil#getBinding(android.view.View))  

### bind

```
T bind (View root, 
                DataBindingComponent bindingComponent)
```

Returns the binding for the given layout root or creates a binding if one does not exist.

Prefer using the generated Binding's`bind`method to ensure type-safe inflation when it is known that`root`has not yet been bound.

<br />

|                                             Parameters                                              ||
|--------------------|---------------------------------------------------------------------------------|
| `root`             | `View`: The root View of the inflated binding layout. <br />                    |
| `bindingComponent` | `DataBindingComponent`: The DataBindingComponent to use in data binding. <br /> |

|                                                     Returns                                                      ||
|-----|-------------------------------------------------------------------------------------------------------------|
| `T` | A ViewDataBinding for the given root View. If one already exists, the existing one will be returned. <br /> |

|                                                                            Throws                                                                             ||
|------------------------------------------------------------------------------------------------------------|---------------------------------------------------|
| [IllegalArgumentException](http://developer.android.com/reference/java/lang/IllegalArgumentException.html) | when root is not from an inflated binding layout. |

**See also:**

- [getBinding(View)](https://developer.android.com/reference/android/databinding/DataBindingUtil#getBinding(android.view.View))  

### convertBrIdToString

```
String convertBrIdToString (int id)
```

Converts the given BR id to its string representation which might be useful for logging purposes.

<br />

|                                 Parameters                                 ||
|------|----------------------------------------------------------------------|
| `id` | `int`: The integer id, which should be a field from BR class. <br /> |

|                                                               Returns                                                                ||
|------------------------------------------------------------------------|--------------------------------------------------------------|
| [String](http://developer.android.com/reference/java/lang/String.html) | The name if the BR id or`null`if id is out of bounds. <br /> |

### findBinding

```
T findBinding (View view)
```

Retrieves the binding responsible for the given View. If`view`is not a binding layout root, its parents will be searched for the binding. If there is no binding,`null`will be returned.

This differs from[getBinding(View)](https://developer.android.com/reference/android/databinding/DataBindingUtil#getBinding(android.view.View))in that findBinding takes any view in the layout and searches for the binding associated with the root.`getBinding`takes only the root view.

<br />

|                     Parameters                     ||
|--------|--------------------------------------------|
| `view` | `View`: A`View`in the bound layout. <br /> |

|                                                    Returns                                                    ||
|-----|----------------------------------------------------------------------------------------------------------|
| `T` | The ViewDataBinding associated with the given view or`null`if view is not part of a bound layout. <br /> |

### getBinding

```
T getBinding (View view)
```

Retrieves the binding responsible for the given View layout root. If there is no binding,`null`will be returned. This uses the DataBindingComponent set in[setDefaultComponent(DataBindingComponent)](https://developer.android.com/reference/android/databinding/DataBindingUtil#setDefaultComponent(android.databinding.DataBindingComponent)).

<br />

|                            Parameters                            ||
|--------|----------------------------------------------------------|
| `view` | `View`: The root`View`in the layout with binding. <br /> |

|                                                                       Returns                                                                        ||
|-----|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `T` | The ViewDataBinding associated with the given view or`null`if either the view is not a root View for a layout or view hasn't been bound. <br /> |

### getDefaultComponent

```
DataBindingComponent getDefaultComponent ()
```

Returns the default[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)used in data binding. This can be`null`if no default was set in[setDefaultComponent(DataBindingComponent)](https://developer.android.com/reference/android/databinding/DataBindingUtil#setDefaultComponent(android.databinding.DataBindingComponent)).

<br />

|                                                                                                                                                                                                                                          Returns                                                                                                                                                                                                                                           ||
|----------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent) | the default[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)used in data binding. This can be`null`if no default was set in[setDefaultComponent(DataBindingComponent)](https://developer.android.com/reference/android/databinding/DataBindingUtil#setDefaultComponent(android.databinding.DataBindingComponent)). <br /> |

### inflate

```
T inflate (LayoutInflater inflater, 
                int layoutId, 
                ViewGroup parent, 
                boolean attachToParent, 
                DataBindingComponent bindingComponent)
```

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.

<br />

|                                                                                                                             Parameters                                                                                                                              ||
|--------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `inflater`         | `LayoutInflater`: The LayoutInflater used to inflate the binding layout. <br />                                                                                                                                                                 |
| `layoutId`         | `int`: The layout resource ID of the layout to inflate. <br />                                                                                                                                                                                  |
| `parent`           | `ViewGroup`: Optional view to be the parent of the generated hierarchy (if attachToParent is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToParent is false.) <br /> |
| `attachToParent`   | `boolean`: Whether the inflated hierarchy should be attached to the parent parameter. If false, parent is only used to create the correct subclass of LayoutParams for the root view in the XML. <br />                                         |
| `bindingComponent` | `DataBindingComponent`: The DataBindingComponent to use in the binding. <br />                                                                                                                                                                  |

|                                                      Returns                                                       ||
|-----|---------------------------------------------------------------------------------------------------------------|
| `T` | The newly-created binding for the inflated layout or`null`if the layoutId wasn't for a binding layout. <br /> |

|                                                                          Throws                                                                           ||
|-----------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [InflateException](http://developer.android.com/reference/android/view/InflateException.html) | When a merge layout was used and attachToParent was false. |

### inflate

```
T inflate (LayoutInflater inflater, 
                int layoutId, 
                ViewGroup parent, 
                boolean attachToParent)
```

Inflates a binding layout and returns the newly-created binding for that layout. This uses the DataBindingComponent set in[setDefaultComponent(DataBindingComponent)](https://developer.android.com/reference/android/databinding/DataBindingUtil#setDefaultComponent(android.databinding.DataBindingComponent)).

Use this version only if`layoutId`is unknown in advance. Otherwise, use the generated Binding's inflate method to ensure type-safe inflation.

<br />

|                                                                                                                            Parameters                                                                                                                             ||
|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `inflater`       | `LayoutInflater`: The LayoutInflater used to inflate the binding layout. <br />                                                                                                                                                                 |
| `layoutId`       | `int`: The layout resource ID of the layout to inflate. <br />                                                                                                                                                                                  |
| `parent`         | `ViewGroup`: Optional view to be the parent of the generated hierarchy (if attachToParent is true), or else simply an object that provides a set of LayoutParams values for root of the returned hierarchy (if attachToParent is false.) <br /> |
| `attachToParent` | `boolean`: Whether the inflated hierarchy should be attached to the parent parameter. If false, parent is only used to create the correct subclass of LayoutParams for the root view in the XML. <br />                                         |

|                                                      Returns                                                       ||
|-----|---------------------------------------------------------------------------------------------------------------|
| `T` | The newly-created binding for the inflated layout or`null`if the layoutId wasn't for a binding layout. <br /> |

|                                                                          Throws                                                                           ||
|-----------------------------------------------------------------------------------------------|------------------------------------------------------------|
| [InflateException](http://developer.android.com/reference/android/view/InflateException.html) | When a merge layout was used and attachToParent was false. |

**See also:**

- [setDefaultComponent(DataBindingComponent)](https://developer.android.com/reference/android/databinding/DataBindingUtil#setDefaultComponent(android.databinding.DataBindingComponent))  

### setContentView

```
T setContentView (Activity activity, 
                int layoutId)
```

Set the Activity's content view to the given layout and return the associated binding. The given layout resource must not be a merge layout.

<br />

|                                                    Parameters                                                     ||
|------------|-------------------------------------------------------------------------------------------------------|
| `activity` | `Activity`: The Activity whose content View should change. <br />                                     |
| `layoutId` | `int`: The resource ID of the layout to be inflated, bound, and set as the Activity's content. <br /> |

|                                                         Returns                                                         ||
|-----|--------------------------------------------------------------------------------------------------------------------|
| `T` | The binding associated with the inflated content view or`null`if the layoutId is not a data binding layout. <br /> |

### setContentView

```
T setContentView (Activity activity, 
                int layoutId, 
                DataBindingComponent bindingComponent)
```

Set the Activity's content view to the given layout and return the associated binding. The given layout resource must not be a merge layout.

<br />

|                                                        Parameters                                                         ||
|--------------------|-------------------------------------------------------------------------------------------------------|
| `activity`         | `Activity`: The Activity whose content View should change. <br />                                     |
| `layoutId`         | `int`: The resource ID of the layout to be inflated, bound, and set as the Activity's content. <br /> |
| `bindingComponent` | `DataBindingComponent`: The DataBindingComponent to use in data binding. <br />                       |

|                                                         Returns                                                         ||
|-----|--------------------------------------------------------------------------------------------------------------------|
| `T` | The binding associated with the inflated content view or`null`if the layoutId is not a data binding layout. <br /> |

### setDefaultComponent

```
void setDefaultComponent (DataBindingComponent bindingComponent)
```

Set the default[DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)to use for data binding.

`bindingComponent`may be passed as the first parameter of binding adapters.

When instance method BindingAdapters are used, the class instance for the binding adapter is retrieved from the DataBindingComponent.

<br />

|                                       Parameters                                        ||
|--------------------|---------------------------------------------------------------------|
| `bindingComponent` | `DataBindingComponent`: The default binding component to use <br /> |

-

  ## Annotations

  - [Bindable](https://developer.android.com/reference/android/databinding/Bindable)
  - [BindingAdapter](https://developer.android.com/reference/android/databinding/BindingAdapter)
  - [BindingConversion](https://developer.android.com/reference/android/databinding/BindingConversion)
  - [BindingMethod](https://developer.android.com/reference/android/databinding/BindingMethod)
  - [BindingMethods](https://developer.android.com/reference/android/databinding/BindingMethods)
  - [InverseBindingAdapter](https://developer.android.com/reference/android/databinding/InverseBindingAdapter)
  - [InverseBindingMethod](https://developer.android.com/reference/android/databinding/InverseBindingMethod)
  - [InverseBindingMethods](https://developer.android.com/reference/android/databinding/InverseBindingMethods)
  - [InverseMethod](https://developer.android.com/reference/android/databinding/InverseMethod)
-

  ## Interfaces

  - [DataBindingComponent](https://developer.android.com/reference/android/databinding/DataBindingComponent)
  - [InverseBindingListener](https://developer.android.com/reference/android/databinding/InverseBindingListener)
  - [Observable](https://developer.android.com/reference/android/databinding/Observable)
  - [ObservableList](https://developer.android.com/reference/android/databinding/ObservableList)
  - [ObservableMap](https://developer.android.com/reference/android/databinding/ObservableMap)
-

  ## Classes

  - [BaseObservable](https://developer.android.com/reference/android/databinding/BaseObservable)
  - [CallbackRegistry](https://developer.android.com/reference/android/databinding/CallbackRegistry)
  - [CallbackRegistry.NotifierCallback](https://developer.android.com/reference/android/databinding/CallbackRegistry.NotifierCallback)
  - [DataBindingUtil](https://developer.android.com/reference/android/databinding/DataBindingUtil)
  - [ListChangeRegistry](https://developer.android.com/reference/android/databinding/ListChangeRegistry)
  - [MapChangeRegistry](https://developer.android.com/reference/android/databinding/MapChangeRegistry)
  - [MergedDataBinderMapper](https://developer.android.com/reference/android/databinding/MergedDataBinderMapper)
  - [Observable.OnPropertyChangedCallback](https://developer.android.com/reference/android/databinding/Observable.OnPropertyChangedCallback)
  - [ObservableArrayList](https://developer.android.com/reference/android/databinding/ObservableArrayList)
  - [ObservableArrayMap](https://developer.android.com/reference/android/databinding/ObservableArrayMap)
  - [ObservableBoolean](https://developer.android.com/reference/android/databinding/ObservableBoolean)
  - [ObservableByte](https://developer.android.com/reference/android/databinding/ObservableByte)
  - [ObservableChar](https://developer.android.com/reference/android/databinding/ObservableChar)
  - [ObservableDouble](https://developer.android.com/reference/android/databinding/ObservableDouble)
  - [ObservableField](https://developer.android.com/reference/android/databinding/ObservableField)
  - [ObservableFloat](https://developer.android.com/reference/android/databinding/ObservableFloat)
  - [ObservableInt](https://developer.android.com/reference/android/databinding/ObservableInt)
  - [ObservableList.OnListChangedCallback](https://developer.android.com/reference/android/databinding/ObservableList.OnListChangedCallback)
  - [ObservableLong](https://developer.android.com/reference/android/databinding/ObservableLong)
  - [ObservableMap.OnMapChangedCallback](https://developer.android.com/reference/android/databinding/ObservableMap.OnMapChangedCallback)
  - [ObservableParcelable](https://developer.android.com/reference/android/databinding/ObservableParcelable)
  - [ObservableShort](https://developer.android.com/reference/android/databinding/ObservableShort)
  - [OnRebindCallback](https://developer.android.com/reference/android/databinding/OnRebindCallback)
  - [PropertyChangeRegistry](https://developer.android.com/reference/android/databinding/PropertyChangeRegistry)
  - [ViewDataBinding](https://developer.android.com/reference/android/databinding/ViewDataBinding)
  - [ViewStubProxy](https://developer.android.com/reference/android/databinding/ViewStubProxy)