首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DataBindingUtil findBinding(视图)与getBinding(视图视图)

DataBindingUtil findBinding(视图)与getBinding(视图视图)
EN

Stack Overflow用户
提问于 2015-07-23 06:33:54
回答 1查看 3.1K关注 0票数 3

findBinding(View view)方法的目的是什么?

我一直在使用测试版。

目前还没有针对各个类的官方参考文档,因此我一直在查看源代码,以了解我们可以访问哪些方法。

DataBindingUtil类有两个方法,听起来好像它们会做类似的事情:

  • public static <T extends ViewDataBinding> T findBinding(View view)
  • public static <T extends ViewDataBinding> T getBinding(View view)

第二个方法getBinding只是一个实用方法,它调用ViewDataBinding类的getBinding方法。

第一种方法findBinding对于跟踪和确定它的用途有点不清楚。有什么想法吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-07-23 17:02:27

对不起,网页中缺少文档,但是它们应该在sdk maven存储库中。

区别在于,查找绑定将遍历父视图,而如果给定视图不是绑定根,则getBinding将返回null。这是文档:

代码语言:javascript
复制
/**
 * 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) {
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31579777

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档