[英]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.