Hey guys,
I was trying to use on-demand feature of
ViewStub
and
OnInflateListener
to listen once the original layout is inflated.
This is my
ViewStub
layout `fragment_navigation_viewstub`:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewStub
android:id="@+id/fragmentNavigationViewStub"
android:layout="@layout/fragment_navigation"
android:layout_width="match_parent"
android:inflatedId="@+id/items_list"
android:layout_height="match_parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
and this is my original layout `fragment_navigation`:
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView
xmlns:android="<http://schemas.android.com/apk/res/android>"
android:id="@+id/items_list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
and my listeneer inside the fragment:
private val binding by viewBinding { FragmentNavigationViewstubBinding.inflate(it) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.fragmentNavigationViewStub.setOnInflateListener { _, view ->
fragmentNavigation = FragmentNavigationBinding.bind(view)
}
}
But I got this exception and looks like
setOnInflateListener
is not called
kotlin.UninitializedPropertyAccessException: lateinit property fragmentNavigation has not been initialized