Databinding is the most commonly used to bind UI views in layout to data source. that is why I decided to use this approach.

Actually, I am to concatenate to of the values from data source and to be shown in view. concatenation is not a big deal I just added "+" operator between the values or variables of the data source.

The problem is how to add space between two of them.

concatenating two of the values by "+" operator was working fine.


  <TextView
                    android:id="@+id/location"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    tools:text="@sample/title"
                    android:text="@{item.location.get(0).getlocation_text + item.location.get(0).city}"
                    android:maxLines="2"
                    android:ellipsize="end"
                    android:gravity="start"
                    android:textAppearance="@style/TextDesc2"
                    card_view:layout_constraintTop_toBottomOf="@+id/title"
                    card_view:layout_constraintStart_toStartOf="parent"
                    card_view:layout_constraintEnd_toEndOf="parent"
                    android:layout_marginTop="8dp" card_view:layout_constraintHorizontal_bias="0.0"/>

I need the result as "locatin_text, city"

but now I am getting "location_textcity"

1 Answers

1
Haresh Ramani On Best Solutions

try this

android:text='@{String.format("%s %s", item.location.get(0).getlocation_text, item.location.get(0).city)}'