2
試圖綁定雙值使用字符串資源以查看。的Android結合雙值,以查看弦使用資源
嘗試1:
layout.xml
android:text="@{@string/user_popularity(Double.toString(user.popularity))}"
string.xml
<string name="user_popularity">Popularity: %s</string>
嘗試2:
layout.xml
android:text="@{String.format(@string/user_popularity, user.popularity)}"
string.xml
<string name="user_popularity">Popularity: %.1f</string>
錯誤:
Error:(167, 107) error: double cannot be dereferenced
這裏有一些類似的問題
當你回答問題時,你有困難嗎?他們看起來像他們回答你的問題,你的嘗試不使用它們。 –
是的,我曾嘗試自提鏈接這兩個解決方案。 – Puni
這應該工作:'機器人:文本= 「@ {@串/ user_popularity(user.popularity)}」'和字符串資源'<字符串名稱= 「user_popularity」>流行度:%1 $ F'假設用戶。流行是一種「雙重」或「浮動」。你在看什麼?是編譯時錯誤,運行時異常還是格式錯誤?這可能是因爲你還沒有使用'binding.setUser()'分配一個用戶。 –