[英]Complex return in Ternary Operator?
我试图在检查元素的状态后返回特定样式的日期,但仍在尝试编写这种方式的确切方法。 我的XML中有一个用于textview的代码:
android:text='@{String.format(item.status.toLowerCase().contains("check") ? ("Scheduled for %s", item.ScheduledDate) : ("Published on %s", item.PublishedDate))}'
但它期望的是+ <> =-而不是,
有人可以帮我正确封装吗?
不幸的是,无论哪个Java类都将内容视图设置为有问题的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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.