AndroidのTextViewの2つの文字列を連結したいのですが、データバインディングAPIで質問する

AndroidのTextViewの2つの文字列を連結したいのですが、データバインディングAPIで質問する

DataBindingAndroid レイアウトでビューを設定するために APIを使用しています。これが私のレイアウトです。

レイアウト.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>

TextViewに表示させたいこんにちはユーザー名データ バインディング API を使用してこれを実現する方法。

ベストアンサー1

連結する重々しいアクセント(`)

android:text="@{`Hello ` + user.firstName}"/>

複数の方法で連結できます。こちらで確認してください。データバインディングを使用してテキストビューで 2 つの文字列を連結する

おすすめ記事