Android 绑定双精度值以使用字符串资源查看

Android binding double value to view using string resources

正在尝试将双精度值绑定到使用字符串资源的视图。

尝试 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

这里有一些类似的问题

其实很简单,我错了。 这是解决方案。

<string name="user_popularity">Popularity: %.1f</string>
android:text="@{@string/user_popularity(user.popularity)}"