Access ViewStub children using view binding

591 views Asked by At

How can I add the layout included in the viewStub to the activity view binding?

main_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/stubContainer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
        <ViewStub
            android:id="@+id/stub"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:inflatedId="@+id/content"
            android:layout="@layout/content_layout" />
</LinearLayout>

And content_layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/content"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <Button
        android:id="@+id/btn"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="button" />
</LinearLayout>

Is there a way to do something like mainLayoutBinding.btn.setOnClickListener()? Or does it have to be using findViewById() after inflating the stub?

0

There are 0 answers