android数据绑定使用“&&"逻辑运算符 [英] android databinding using "&&" logical operator

查看:712
本文介绍了android数据绑定使用“&&"逻辑运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use the and "&&" operator in xml using Android databinding,

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

但是我得到了编译错误:

but I got the compilation error:

错误:任务':app:dataBindingProcessLayoutsDevDebug'的执行失败. org.xml.sax.SAXParseException; systemId:文件:/Users/path/app/build/intermediates/res/merged/dev/debug/layout/fragment_space.xml; lineNumber:106; columnNumber:89;实体名称必须紧跟在&"之后在实体参考中.

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中的红色突出显示错误未转义的字符或非终止字符".

and red highlight error in android studio "unescaped & or non terminated character".

那我该如何解决呢?

修改: 找到答案后,这些字符需要转义:

found the answer, these character needs to be escaped:

'&' --> '&'

'<' --> '&lt;'

'>' --> '&gt;'

推荐答案

&&应该呈现为&amp;&amp;.

官方数据绑定指南包含以下示例使用这些XML实体的比较运算符,例如

The official data binding guide has examples of comparison operators where these XML entities are used, for example

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

修改

自从编写答案以来,我在答案中提到的示例表达式就从文档的英文版中消失了.它们确实可以在一些过时的非英语版本文档中生存,例如西班牙语版本.

The example expressions I mentioned in the answer disappeared from the English version of the docs since this answer was written. They do survive in some outdated non-English versions of the docs such as the Spanish version.

无论哪种方式,原始答案仍然有效,因为在XML中使用XML实体是XML的标准,并且与Android本身无关.

Either way, the original answer is still valid, because the use of XML entities in XML is standard in XML and has nothing to do with Android itself.

这篇关于android数据绑定使用“&amp;&amp;"逻辑运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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