Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat two dynamic strings using Data Binding

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.

like image 462
Igor Mańka Avatar asked Feb 27 '17 15:02

Igor Mańka


Video Answer


1 Answers

Try it like this instead

android:text='@{userdata.firstName+" "+userdata.lastName}' 

or alternately...

android:text='@{String.format("%s %s", userdata.firstName, userdata.lastName)}'
like image 160
Carl Poole Avatar answered Oct 30 '22 13:10

Carl Poole