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

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

问题描述

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

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

但是我得到了编译错误:

<块引用>

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

android studio 中的红色高亮错误未转义 & 或非终止字符".

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

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

'&'-->'&''<'-->'<''>'-->'>'

解决方案

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

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

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

编辑

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

无论如何,原来的答案仍然有效,因为在 XML 中使用 XML 实体是 XML 中的标准,与 Android 本身无关.

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:

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.

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

So how should I fix this?

Edit: found the answer, these character needs to be escaped:

'&' --> '&amp;'

'<' --> '&lt;'

'>' --> '&gt;'

解决方案

&& should be rendered as &amp;&amp;.

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}"

Edit

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.

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天全站免登陆