Search code examples
androidkotlindata-bindingandroid-databinding

Android databinding with Kotlin map


This is a basic question that for some reason Google doesn't seem to have the answer. I'm trying to use a Kotlin map object with databinding for xml. How the heck do I import the Map object in the xml? Using

            name="formIds"
            type="kotlin.collections.MapsKt" />

doesn't import the map object. I get a Failed to resolve Bracked Expr formIds["Submit"], target: kotlin.collections.MapsKt when I try to use the object.

I create formIds as follows:

val _formIds =
        mapOf<FormType, Map<String, Int>>(...

Anyone know?


Solution

  • type="kotlin.collections.MapsKt" is not enought for databinding. Declare it explictly with types and provide import if required. For example type="java.util.HashMap&lt;String, Integer&gt;"