Is it possible to concat two dynamic strings using Data Binding?
My code looks like:
<TextView
android:id="@+id/text_view_activity_profile_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/image_view_activity_profile_small_photo"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:text="@={userdata.firstName+' '+userdata.lastName}"
android:textColor="@color/white"
android:textSize="24sp" />
,but it is not the correct way : Error:(52, 42) The expression (firstNameUserdataCha) + (lastNameUserdata) cannot cannot be inverted: Two way binding with operator + supports only a single dynamic expressions.
Try it like this instead
android:text='@{userdata.firstName+" "+userdata.lastName}'
or alternately...
android:text='@{String.format("%s %s", userdata.firstName, userdata.lastName)}'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With