I'm using MVVM framework for Android application with data-binding library.
I have some reusable compoments, that should have every activity. f.e. toolbar, menu, floating action button.
I want to create a generic activity, that will implement all these reusable features and then every activity class will be inherited from this generic activity. I also have GenericViewModel class and every other ViewModel is inherited from this generic class.
But I have a problem with layout. I want to create generic layout file and include there sublayout dinamically. f.e.
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="data"
type="com.mypackage.genericViewModel" />
</data>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include
bind:data="@{data}"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
layout="@{Here i want to have dynamic variable}"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout></layout>
I do not want to copy / paste this code for each activity, but data-binding library does not allow to include layout dynamically. Is there any solution for such cases?