尝试使用字符串资源将 double 值绑定(bind)到 View 。
尝试 1:
布局.xml
android:text="@{@string/user_popularity(Double.toString(user.popularity))}"
字符串.xml
<string name="user_popularity">Popularity: %s</string>
尝试 2:
布局.xml
android:text="@{String.format(@string/user_popularity, user.popularity)}"
字符串.xml
<string name="user_popularity">Popularity: %.1f</string>
错误:
Error:(167, 107) error: double cannot be dereferenced
这里有一些类似的问题
最佳答案
其实很简单,可惜我方法不对。 这是解决方案。
<string name="user_popularity">Popularity: %.1f</string>
android:text="@{@string/user_popularity(user.popularity)}"
关于Android使用字符串资源绑定(bind)双值来查看,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45467052/