Reputation: 15738
How to concatenate string in data binding. I want to show both firstName and lastName is same TextView. Any help thanks in advance.
<data>
<variable
name="task"
type="com.myapp.app.Task" />
</data>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:drawablePadding="6dp"
android:ellipsize="end"
android:gravity="center"
android:maxLines="1"
android:text="@={task.assignedTo.firstName}"//how to include lastname
android:textColor="@color/textBlack"
android:textSize="14sp"
tools:text="Saikiran" />
Upvotes: 1
Views: 1357
Reputation: 35569
First of all there should not be =
after @
because it indicates two-way binding and there is no meaning of two-way binding with TextView
.
To concate last name you can use +
operator
android:text="@{task.assignedTo.firstName + task.assignedTo.lastName}"
and to concate it with some custom String :
android:text="@{task.assignedTo.firstName + ` - ` + task.assignedTo.lastName}"
Upvotes: 6