Reputation: 23
I use DataBinding
in fragment
,but there are some trouble
this is the fragment
and this is my layout
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</layout>
how can I fix this?
Upvotes: 1
Views: 1535
Reputation: 531
You must wrap your layout in a layout
tag:
<layout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<layout>
Also ensure that you enable databinding in your module's build.gradle file:
dataBinding {
enabled true
}
And note that you named your binding variable inflate
but you use binding.getRoot()
in the return statement. So rename your variable to binding
. Or change your return statement to return inflate.getRoot();
Whatever you prefer.
Upvotes: 2