As Kotlin Synthetics is deprecated, we are migrating to ViewBinding.
I have tried a lot of googling and reading documentation on ViewStub, ViewBinding and have implemented ViewBinding for Fragments Activities, include, merge tags however I could not find any way to inflate the ViewStub using ViewBinding.
<ViewStub
android:id="@+id/viewStubLayout"
tools:layout="@layout/view_demo_layout" />
Please ignore the width and height attributes for this they were added as a style and have been removed from this snippet.
Can you please share how to inflate this view with another xml layout dynamically using ViewBinding.
Even in the ViewStub.java file, the class level comments state that,
The preferred way to perform the inflation of the layout resource is the following:
ViewStub stub = findViewById(R.id.stub); View inflated = stub.inflate();
Does this mean that, I have to keep using R.layout.xxx_xx to inflate the viewstub. Can't I use the binding object for that particular xml file to inflate the view ?
stub.inflate()
. If you want binding object the you can get it byDataBindingUtil.bind(inflated)
. – FryerViewDemoLayoutBinding.bind()
on your binding class instead of DataBindingUtil . – Fryer