Sasank Sunkavalli Sasank Sunkavalli - 1 year ago 122
Android Question

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

Im using

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

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="user" type="testing.sampleapp.com.sampleapp.User"/>
</data>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{ "Hello " + user.firstName}"/>
</LinearLayout>




I want the TextView to display Hello UserName. How to achieve this using the data binding api.

Answer Source

concate it with grave accent (`)

android:text="@{`Hello ` + user.firstName}"/>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download