如何在 android 数据绑定中使用逻辑操作?

How can I use logical operations in android data binding?

在我的布局文件中,我尝试使用以下语法来指定 TextView 中的文本:

android:text="@{user.isMe() && user.status.isEmpty() ? @string/EmptyStatusHint : user.status}"/>

我得到:

[Fatal Error] fragment_user_profile.xml:142:58: The entity name must immediately follow the '&' in the entity reference.

Data Binding Guide中没有什么特别之处。

所以,对于这种情况,我有两个问题:

  1. 如何使用 xml 中的逻辑语句进行数据绑定?
  2. 报错中提到的“entity”是什么?我想我应该知道 ))

您必须将 && 写成 &&