I have read the following Android include layout dynamically with data-binding library question. My problem is a bit different.
I have two xml one for the the Activity:
<?xml version="1.0" encoding="utf-8"?>
<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="item" type="myapplication.MainActivityViewModel"/>
</data>
<android.support.constraint.ConstraintLayout
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="myapplication.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main">
</FrameLayout>
</android.support.constraint.ConstraintLayout>
</layout>
And another for a frame:
<layout
xmlns:android="http://schemas.android.com/apk/res/android">
<data>
<variable name="item" type="myapplication.FrameViewModel"/>
</data>
<FrameLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST"/>
</FrameLayout>
</layout>
I would like to inflate the frame.xml dynamically to the activities FrameLayout with databinding. In other words I would like to inflate different frames in the activity, just like Fragment, without fragments. I tried the following in the Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActivityMainBinding activityMainBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);
ViewGroup view = activityMainBinding.main;
FrameBinding frameBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.frame,view, false);
}
With that code I can get both layout showing in the Activity. I only can see the Activities layout. How should I change my code to be able to see my Activity layout view elements and my frame view elements as well in the Activity?