Let's say I have the following layout files:
first_layout.xml
<layout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First layout title"/>
<include
layout="@layout/reusable_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</layout>
second_layout.xml
<layout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/title_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Second layout title"/>
<include
layout="@layout/reusable_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</layout>
reusable_layout.xml
<layout>
<TextView
android:id="@+id/text_to_replace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="replace me"/>
</layout>
...and that I have two different ViewModels (FirstLayoutViewModel and SecondLayoutViewModel, each with a different String property). I want to use Data Binding to bind each ViewModel's string property to the text_to_replace element in reusable_layout.xml.
How can I do this? Normally, I would declare a variable in a <data> tag and assign the type to the appropriate ViewModel but how can I do this if the layout (reusable_layout.xml) is being used multiple times? How will it know which ViewModel type to use?
In this example, I could just use a different TextView for the first_layout and second_layout layout instead of importing a layout but in my real project, the layout I want to reuse is much more complicated and it makes sense to reuse.
Any help would be great. Thanks!