I want to concat two strings for a TextView in android, Data Binding Api

前端 未结 10 775
太阳男子
太阳男子 2020-12-23 14:04

Im using DataBinding Api for setting the views in android layouts. Here is my layout.

layout.xml



        
相关标签:
10条回答
  • 2020-12-23 15:03

    concate it with grave accent (`)

    android:text="@{`Hello ` + user.firstName}"/>
    

    You can concat it in multiple ways, check it here concat-two-strings-in-textview-using-databinding

    0 讨论(0)
  • 2020-12-23 15:05

    In case of static string and other dynamic you can use this

    android:text="@{`Hello ` + user.firstName}"/>
    

    In case of dynamic data you can use this.

    android:text='@{user.firstName+" "+user.lastName}'
    
    0 讨论(0)
  • 2020-12-23 15:06

    if you want to concat String resource with data from your model, you can do it in such way:

     android:text='@{@string/release_date+model.release_date}'
    
    0 讨论(0)
  • 2020-12-23 15:06

    The simplest way I found to be is to replace ''(single) in place of ""(double), For Eg. You have two variables,

    <variable name="a" type="String" />
    <variable name="b" type="String" />
    

    Now to concatenate,

    android:text='a + " " + b}'
    
    0 讨论(0)
提交回复
热议问题