Search code examples
androidandroid-studiokotlinanko

Android Anko alert with custom view error (Kotlin)


I want to create an alert dialog with custom elements using anko.

Every guide and tutorial I've found uses this method:

alert {
    customView {
        textView("Hello")
    }
}.show()

But I get an error in customView saying:

Error:(73, 13) Type inference failed: Not enough information to infer parameter T in inline fun <reified T : View> Activity.customView(theme: Int = ..., init: T.() -> Unit): T
Please specify it explicitly.

Has something changed in Anko and has not being documented?


Solution

  • You should pick the second item that Android Studio suggests you -

    'customView for AlertBuilder<*> in org.jetbrains.anko'

    enter image description here