gpt4 book ai didi

android数据绑定(bind)使用 "&&"逻辑运算符

转载 作者:IT老高 更新时间:2023-10-28 13:04:48 28 4
gpt4 key购买 nike

我正在尝试使用 Android 数据绑定(bind)在 xml 中使用 and "&&"运算符,

android:visibility="@{(bean.currentSpaceId == bean.selectedSpaceId **&&** bean.currentSpaceId > 0)? View.VISIBLE: View.GONE}"

但我得到了编译错误:

Error:Execution failed for task ':app:dataBindingProcessLayoutsDevDebug'. org.xml.sax.SAXParseException; systemId: file:/Users/path/app/build/intermediates/res/merged/dev/debug/layout/fragment_space.xml; lineNumber: 106; columnNumber: 89; The entity name must immediately follow the '&' in the entity reference.

android studio 中出现红色高亮错误“未转义 & 或非终止字符”。

那么我应该如何解决这个问题?

编辑:找到答案了,这些字符需要转义:

'&' --> '&'

'<' --> '&lt;'

'>' --> '&gt;'

最佳答案

&& 应呈现为 &&

官方data binding guide有使用这些 XML 实体的比较运算符的示例,例如

android:visibility="@{age &lt; 13 ? View.GONE : View.VISIBLE}"

编辑

自从写了这个答案以来,我在答案中提到的示例表达式从文档的英文版中消失了。它们确实存在于一些过时的非英语版本的文档中,例如西类牙语版本。

不管怎样,原来的答案仍然有效,因为在XML中使用XML实体是XML中的标准,与Android本身无关。

关于android数据绑定(bind)使用 "&&"逻辑运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37152824/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com