How to use Kotlin Android Extensions with ViewStub properly?

1.1k views Asked by At

Does the extensions have a magic to call inflated view? As far as I see, I should break the harmony of code and call findViewById.

The intent was to inflate layout_ongoingView layout at sometime, and make hidden, and visible again based on scenario.

<ViewStub
    android:id="@+id/viewStubOngoing"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inflatedId="@+id/ongoingView"
    android:layout="@layout/layout_ongoingView" />

And codes

override fun hideOngoingPanel() {
    if (viewStubOngoing !is ViewStub) {
        findViewById(R.id.ongoingView).visibility = View.GONE
    }
}

override fun showOngoingPanel() {
    if (viewStubOngoing !is ViewStub) {
        findViewById(R.id.ongoingView).visibility = View.VISIBLE
    } else {
        viewStubOngoing.inflate()
    }
}
0

There are 0 answers