Reputation: 1051
I am using data binding to fill the text attribute of my TextView:
android:text="@{String.valueOf(todaysData.totalYield)}"
This works fine. Now I would like to a fixed text before but I have no clue if that is possible in xml. I tried:
android:text="Totals: @{String.valueOf(todaysData.totalYield)}"
android:text="Totals: {String.valueOf(todaysData.totalYield)}"
but in both cases the bound value is no longer used but the whole expression is displayed.
Is it possible to combine fixed and bound text parts in xml?
Cheers
Upvotes: 0
Views: 189
Reputation: 247
Yes you can do That by doing the following:
android:text= "@{@string/generic_text(todaysData.totalYield)}"
and then in your strings you will have:
<string name="generic_text">My Name is %s</string>
Or you can also do the following:
android:text="@{`Totals: ` + todaysData.totalYield}"
Upvotes: 2