How to use Kotlin Android Extensions with ViewStub properly?
Asked Answered
A

0

11

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()
    }
}
Alienism answered 27/8, 2017 at 11:40 Comment(1)
Did you find any solution besides the ugly findViewById? Facing the same issue now...Chartist

© 2022 - 2024 — McMap. All rights reserved.