Most visited

Recently visited

DataBindingUtil

public class DataBindingUtil
extends Object

java.lang.Object
   ↳ android.databinding.DataBindingUtil


实用程序类从布局创建 ViewDataBinding

Summary

Public methods

static <T extends ViewDataBinding> T bind(View root)

返回给定布局根的绑定,或者创建一个不存在的绑定。

static <T extends ViewDataBinding> T bind(View root, DataBindingComponent bindingComponent)

返回给定布局根的绑定,或者创建一个不存在的绑定。

static String convertBrIdToString(int id)

将给定的BR ID转换为可能对记录有用的字符串表示。

static <T extends ViewDataBinding> T findBinding(View view)

检索负责给定View的绑定。

static <T extends ViewDataBinding> T getBinding(View view)

检索负责给定视图布局根的绑定。

static DataBindingComponent getDefaultComponent()

返回数据绑定中使用的默认值 DataBindingComponent

static <T extends ViewDataBinding> T inflate(LayoutInflater inflater, int layoutId, ViewGroup parent, boolean attachToParent, DataBindingComponent bindingComponent)

膨胀一个绑定布局并返回该布局的新创建的绑定。

static <T extends ViewDataBinding> T inflate(LayoutInflater inflater, int layoutId, ViewGroup parent, boolean attachToParent)

膨胀一个绑定布局并返回该布局的新创建的绑定。

static <T extends ViewDataBinding> T setContentView(Activity activity, int layoutId)

将活动的内容视图设置为给定的布局并返回关联的绑定。

static <T extends ViewDataBinding> T setContentView(Activity activity, int layoutId, DataBindingComponent bindingComponent)

将活动的内容视图设置为给定的布局并返回关联的绑定。

static void setDefaultComponent(DataBindingComponent bindingComponent)

设置默认的 DataBindingComponent用于数据绑定。

Inherited methods

From class java.lang.Object

Public methods

bind

T bind (View root)

返回给定布局根的绑定,或者创建一个不存在的绑定。 这使用setDefaultComponent(DataBindingComponent)设置的DataBindingComponent。

当已知 root尚未绑定时,首选使用生成的Binding的 bind方法来确保类型安全的通货膨胀。

Parameters
root View: The root View of the inflated binding layout.
Returns
T A ViewDataBinding for the given root View. If one already exists, the existing one will be returned.
Throws
IllegalArgumentException when root is not from an inflated binding layout.

也可以看看:

bind

T bind (View root, 
                DataBindingComponent bindingComponent)

返回给定布局根的绑定,或者创建一个不存在的绑定。

当已知 root尚未绑定时,首选使用生成的Binding的 bind方法来确保类型安全的通货膨胀。

Parameters
root View: The root View of the inflated binding layout.
bindingComponent DataBindingComponent: The DataBindingComponent to use in data binding.
Returns
T A ViewDataBinding for the given root View. If one already exists, the existing one will be returned.
Throws
IllegalArgumentException when root is not from an inflated binding layout.

也可以看看:

convertBrIdToString

String convertBrIdToString (int id)

将给定的BR ID转换为可能对记录有用的字符串表示。

Parameters
id int: The integer id, which should be a field from BR class.
Returns
String The name if the BR id or null if id is out of bounds.

findBinding

T findBinding (View view)

检索负责给定View的绑定。 如果view不是绑定布局根目录,则会搜索它的父级绑定。 如果没有绑定,则返回null

这与getBinding(View)不同, getBinding(View)在布局中使用任何视图并搜索与根相关联的绑定。 getBinding只接受根视图。

Parameters
view View: A View in the bound layout.
Returns
T The ViewDataBinding associated with the given view or null if view is not part of a bound layout.

getBinding

T getBinding (View view)

检索负责给定视图布局根的绑定。 如果没有绑定,则返回null 这使用setDefaultComponent(DataBindingComponent)设置的DataBindingComponent。

Parameters
view View: The root View in the layout with binding.
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.

getDefaultComponent

DataBindingComponent getDefaultComponent ()

返回数据绑定中使用的默认值DataBindingComponent 如果null没有设置默认值,则这可以是setDefaultComponent(DataBindingComponent)

Returns
DataBindingComponent the default DataBindingComponent used in data binding. This can be null if no default was set in setDefaultComponent(DataBindingComponent).

inflate

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

膨胀一个绑定布局并返回该布局的新创建的绑定。

仅当layoutId未知layoutId时才使用此版本。 否则,使用生成的绑定的膨胀方法来确保类型安全的膨胀。

Parameters
inflater LayoutInflater: The LayoutInflater used to inflate the binding layout.
layoutId int: The layout resource ID of the layout to inflate.
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.)
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.
bindingComponent DataBindingComponent: The DataBindingComponent to use in the binding.
Returns
T The newly-created binding for the inflated layout or null if the layoutId wasn't for a binding layout.
Throws
InflateException When a merge layout was used and attachToParent was false.

inflate

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

膨胀一个绑定布局并返回该布局的新创建的绑定。 这使用setDefaultComponent(DataBindingComponent)设置的DataBindingComponent。

仅当layoutId未知layoutId时才使用此版本。 否则,使用生成的绑定的膨胀方法来确保类型安全的膨胀。

Parameters
inflater LayoutInflater: The LayoutInflater used to inflate the binding layout.
layoutId int: The layout resource ID of the layout to inflate.
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.)
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.
Returns
T The newly-created binding for the inflated layout or null if the layoutId wasn't for a binding layout.
Throws
InflateException When a merge layout was used and attachToParent was false.

也可以看看:

setContentView

T setContentView (Activity activity, 
                int layoutId)

将活动的内容视图设置为给定的布局并返回关联的绑定。 给定的布局资源不能是合并布局。

Parameters
activity Activity: The Activity whose content View should change.
layoutId int: The resource ID of the layout to be inflated, bound, and set as the Activity's content.
Returns
T The binding associated with the inflated content view.

setContentView

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

将活动的内容视图设置为给定的布局并返回关联的绑定。 给定的布局资源不能是合并布局。

Parameters
activity Activity: The Activity whose content View should change.
layoutId int: The resource ID of the layout to be inflated, bound, and set as the Activity's content.
bindingComponent DataBindingComponent: The DataBindingComponent to use in data binding.
Returns
T The binding associated with the inflated content view.

setDefaultComponent

void setDefaultComponent (DataBindingComponent bindingComponent)

设置默认的 DataBindingComponent用于数据绑定。

bindingComponent可以作为绑定适配器的第一个参数传递。

当使用实例方法BindingAdapters时,将从DataBindingComponent中检索绑定适配器的类实例。

Parameters
bindingComponent DataBindingComponent

Hooray!