[英]Android data binding ternary operator error
I'm trying to bind the enabled
value of an ImageView
using data binding with an ObservableInt
in a ternary operator like this: 我正在尝试使用像这样的三元运算符中的ObservableInt
与数据绑定来绑定ImageView
的enabled
值:
<variable
name="myInt"
type="android.databinding.ObservableInt"/>
...
<ImageView
...
android:enabled='@{myInt > 1 ? false : true}'
...
/>
It works exactly as expected. 它完全按预期工作。
But when I change the expression to 但是当我将表达式更改为
android:enabled='@{myInt < 1 ? false : true}'
It throws the following compilation error: 它将引发以下编译错误:
The value of attribute "android:enabled" associated with an element type "ImageView" must not contain the '<' character. 与元素类型“ ImageView”关联的属性“ android:enabled”的值不得包含“ <”字符。
Why can I check if myInt
is larger than 1 but can't check if it's smaller than 1? 为什么我要检查myInt
是否大于1,但不能检查是否小于1?
您需要为xml转义字符,如下所示:
android:enabled="@{myInt < 1 ? false : true}"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.