DataBindingUtil findBinding(查看视图)与 getBinding(查看视图)
DataBindingUtil findBinding(View view) vs getBinding(View view)
方法 findBinding(View view)
的预期目的是什么?
我一直在使用数据绑定库测试版。
目前还没有针对个人 classes 的官方参考文档,所以我一直在查看源代码以了解我们可以访问哪些方法。
DataBindingUtil class 有两个方法,听起来它们会做类似的事情:
public static <T extends ViewDataBinding> T findBinding(View view)
public static <T extends ViewDataBinding> T getBinding(View view)
第二种方法getBinding
只是调用ViewDataBinding
class'getBinding
方法的实用方法。
第一种方法findBinding
有点不清楚,无法遵循和确定其目的。有什么想法吗?
抱歉,网页中缺少文档,但它们应该在 sdk maven 存储库中。
不同之处在于,如果给定视图不是绑定根,则 find 绑定将遍历父级,而 getBinding 将 return null
。以下是文档:
/**
* Retrieves the binding responsible for the given View. If <code>view</code> is not a
* binding layout root, its parents will be searched for the binding. If there is no binding,
* <code>null</code> will be returned.
* <p>
* This differs from {@link #getBinding(View)} in that findBinding takes any view in the
* layout and searches for the binding associated with the root. <code>getBinding</code>
* takes only the root view.
*
* @param view A <code>View</code> in the bound layout.
* @return The ViewDataBinding associated with the given view or <code>null</code> if
* view is not part of a bound layout.
*/
public static <T extends ViewDataBinding> T findBinding(View view) {
/**
* Retrieves the binding responsible for the given View layout root. If there is no binding,
* <code>null</code> will be returned. This uses the DataBindingComponent set in
* {@link #setDefaultComponent(DataBindingComponent)}.
*
* @param view The root <code>View</code> in the layout with binding.
* @return The ViewDataBinding associated with the given view or <code>null</code> if
* either the view is not a root View for a layout or view hasn't been bound.
*/
public static <T extends ViewDataBinding> T getBinding(View view) {
方法 findBinding(View view)
的预期目的是什么?
我一直在使用数据绑定库测试版。
目前还没有针对个人 classes 的官方参考文档,所以我一直在查看源代码以了解我们可以访问哪些方法。
DataBindingUtil class 有两个方法,听起来它们会做类似的事情:
public static <T extends ViewDataBinding> T findBinding(View view)
public static <T extends ViewDataBinding> T getBinding(View view)
第二种方法getBinding
只是调用ViewDataBinding
class'getBinding
方法的实用方法。
第一种方法findBinding
有点不清楚,无法遵循和确定其目的。有什么想法吗?
抱歉,网页中缺少文档,但它们应该在 sdk maven 存储库中。
不同之处在于,如果给定视图不是绑定根,则 find 绑定将遍历父级,而 getBinding 将 return null
。以下是文档:
/**
* Retrieves the binding responsible for the given View. If <code>view</code> is not a
* binding layout root, its parents will be searched for the binding. If there is no binding,
* <code>null</code> will be returned.
* <p>
* This differs from {@link #getBinding(View)} in that findBinding takes any view in the
* layout and searches for the binding associated with the root. <code>getBinding</code>
* takes only the root view.
*
* @param view A <code>View</code> in the bound layout.
* @return The ViewDataBinding associated with the given view or <code>null</code> if
* view is not part of a bound layout.
*/
public static <T extends ViewDataBinding> T findBinding(View view) {
/**
* Retrieves the binding responsible for the given View layout root. If there is no binding,
* <code>null</code> will be returned. This uses the DataBindingComponent set in
* {@link #setDefaultComponent(DataBindingComponent)}.
*
* @param view The root <code>View</code> in the layout with binding.
* @return The ViewDataBinding associated with the given view or <code>null</code> if
* either the view is not a root View for a layout or view hasn't been bound.
*/
public static <T extends ViewDataBinding> T getBinding(View view) {