How do I use databinding to combine a string from resources with a dynamic variable in XML?

前端 未结 9 956
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-07 13:30

I have a TextView which has a hardcoded string and I have a dynamic variable that I want to put at the end of this string. This is my code:



        
9条回答
  •  情书的邮戳
    2020-12-07 14:14

    You can also set string resource as parameter to other string resource using formatter like below:

    Hello
    World
    %s lovely %s
    

    and

    android:text="@{String.format(@string/formatted_text, @string/first_param_text, @string/second_param_text)}"
    

    "Hello lovely World" will appear on the view.

提交回复
热议问题