问题
I'm using android data binding and it is working fine whenever I'm not using the include tag.
If I included a view using the tag (even it is displaying on the app) but the data binding object doesn't recognize the views of the included layout. These are my layout files.
internet_unavailable.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/internet_textview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:gravity="center_horizontal"
android:text="@string/msg_internet_unavailable"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/colorSecondaryText" />
<Button
android:id="@+id/internet_button_retry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="@dimen/internet_margin_top"
android:backgroundTint="@color/colorAccent"
android:paddingEnd="@dimen/internet_padding_h"
android:paddingStart="@dimen/internet_padding_h"
android:text="@string/str_retry"
android:textColor="@android:color/white" />
</LinearLayout>
</layout>
fragment.xml
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.ncimsl.fragments.ProgressNotesFragment">
<include
android:id="@+id/progress_notes_internet"
layout="@layout/internet_unavailable" />
<ProgressBar
android:id="@+id/progress_notes_progressbar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/progress_notes_swiperefreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/progress_notes_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
</layout>
As you can see the progressBar, swipeRefreshLayout and the recyclerView are displaying at the suggestions except the included layout and the views inside it.
Any idea to fix this?
回答1:
Thanks Guys. I think it was an issue in Android Studio of my PC. I opened the project on another PC and now it's working. Probably I should re-install the Android Studio and give a try.
回答2:
Performing Rebuild solves the issue for me.
Following is the screenshot from my AndroidStudio after Rebuild:
My build.gradle:
android{
...
dataBinding {
enabled = true
}
}
My gradle.properties:
android.databinding.enableV2=true
来源:https://stackoverflow.com/questions/49940894/android-data-binding-with-include-tag-doesnt-work