android - 数据绑定(bind) : Choose one of string resources depends on condition

标签 android android-databinding

我的数据对象中有一个 bool 变量,当它为 true 时,希望显示资源中的 1 个字符串,当它为 false 时,显示另一个字符串。 我正在尝试这样做:

android:text="@{sendit.bccMode ? @string/sharebox.bcc_mode_on : @string/sharebox.bcc_mode_off}"

但是出现编译错误:

****/ data binding error ****msg:Could not find accessor java.lang.String.bcc_mode_on

我做错了什么?

最佳答案

当您使用 . (点)作为名称,将您的 strings.xml 文件更改为:

  <string name="sharebox_bcc_mode_on">BCC mode on</string>
  <string name="sharebox_bcc_mode_off">BCC mode off</string>

关于android - 数据绑定(bind) : Choose one of string resources depends on condition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43872962/

相关文章:

java - SAX 解析器的 endElement() 中不显示的字符

android - 删除 ListView 标题和第一项之间的分隔符

android - 为什么数据绑定(bind)不像 android 命名空间的自定义名称

Android数据绑定(bind),无法生成 View 绑定(bind)

android - ObservableField 不传播更改

java - 获取 javax.annotation.processing.Processor 中 VariableElement 的封闭类名

android - setImageViewBitmap 在 android 小部件中不起作用

java - 搜索栏无法正常工作

android - Gradle 无法解析生成的类

android - 如何在Android中获取ObservableField的值