三元运算符中的复杂 return?

Complex return in Ternary Operator?

我在检查元素的状态后尝试 return 一个特定样式的日期,但一直在努力寻找正确的写法。 我的 XML:

中有此文本视图代码
android:text='@{String.format(item.status.toLowerCase().contains("check") ?  ("Scheduled for %s", item.ScheduledDate) : ("Published on %s", item.PublishedDate))}'

但它期望 +<>=- 而不是 ,

有人可以帮我正确封装吗?

不幸的是,您必须从 Java class 将内容视图设置为有问题的 xml 文件的任何一个中执行此操作。

像这样:

    TextView tv = (TextView) findViewById(R.id.textview);
    String text = (item.status.toLowerCase().contains("check") ? String.format("Scheduled for %1$s", item.ScheduledDate) : String.format("Published on %1$s", item.PublishedDate);
    tv.setText(text);