Im DataBinding
を使用して、アンドロイドレイアウトのビューを設定します。ここに私のレイアウトです。アンドロイドのTextView用に2つの文字列を連結したい場合、データバインディングApi
<?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>
layout.xml私はTextViewにはこんにちはユーザー名を表示したいです。どのようにデータバインディングAPIを使用してこれを達成する。 墓アクセント( `)
android:text="@{`Hello ` + user.firstName}"/>
うんうん。ありがとう。私は単一の反転したカンマ( ')を使用していました。重大なアクセント( ')が私のために働いた。 –
@SasankSunkavalliはあなたを助けてうれしいです:)、DataBindingを使用するときは常に文字列に重大なアクセントを使用してください。 –