AntonSack
AntonSack

Reputation: 1051

Kotlin/Android: Text of TextView - fixed and bound part

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

Answers (1)

Pako1
Pako1

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

Related Questions