Reputation: 1294
Trying to bind double value to view using string resources.
Attempt 1:
layout.xml
android:text="@{@string/user_popularity(Double.toString(user.popularity))}"
string.xml
<string name="user_popularity">Popularity: %s</string>
Attempt 2:
layout.xml
android:text="@{String.format(@string/user_popularity, user.popularity)}"
string.xml
<string name="user_popularity">Popularity: %.1f</string>
Error:
Error:(167, 107) error: double cannot be dereferenced
Here are some similar questions
Upvotes: 2
Views: 1744
Reputation: 1294
Actually it was quite simple, my bad I was doing the wrong way. Here's the solution.
<string name="user_popularity">Popularity: %.1f</string>
android:text="@{@string/user_popularity(user.popularity)}"
Upvotes: 4