无法在Android数据绑定中引用其他View ID [英] Cannot refer to other View ID in Android data binding

查看:95
本文介绍了无法在Android数据绑定中引用其他View ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚看完高级数据绑定-Google I/O 2016 ,并想申请以下内容可减少在不同视图中重复使用我的表情.

I just finished watching Advanced Data Binding - Google I/O 2016 and would like to apply the following to reduce repetition of my expression used in different views.

但是我无法在我的情况下起作用:

But I cannot make it work in my case:

<ImageButton
                android:id="@+id/btn_list"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:layout_gravity="start"
                android:background="@drawable/btn_s01_list"
                android:visibility="@{bean.shouldHideControls? View.GONE: View.VISIBLE}"/>

            <ToggleButton
                android:id="@+id/btn_radar"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@drawable/btn_radar_selector"
                android:checked="false"
                android:gravity="end"
                android:text=""
                android:textOff=""
                android:textOn=""
                android:visibility="@{btn_list.visibility}"/>

我知道了

错误:(426,39)标识符必须具有XML中的用户定义类型 文件. btn_list丢失了

Error:(426, 39) Identifiers must have user defined types from the XML file. btn_list is missing it

我错过了同一个谈话的重点... View ID是驼峰化的.

I missed an important point in the same talk... The View IDs are camel-casified.

推荐答案

绑定过程将您的ID转换为绑定类中的属性,并且生成的名称是驼峰化的.

The binding process converts your IDs to properties in the binding class, and the generated names are camel-casified.

您可能需要更改以下行:

You may need to change the following line:

android:visibility="@{btn_list.visibility}"/>

对此:

android:visibility="@{btnList.visibility}"/>

这篇关于无法在Android数据绑定中引用其他View ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆