'How to pass sealed data class in xml data binding?

In my view model I have a method onEvent() which get as parameter an Event

Event class is a sealed class with objects and data classes:

sealed class Event {
    data class TextChanged(val text: String) : Event()
    object OkButtonClicked : Event() //ok with INSTANCE at the end.
}

now I want to call vm.onEvent() method with TextChanged as a param. And isn't working when I add: app:onTextChanged="@{(text,start, before, count)-> vm.onEvent(Event.TextChanged(text.toString()))}"

With OkButtonClicked I use android:onClick="@{() -> vm.onEvent(Event.OkButtonClicked.INSTANCE)}" and it works fine.

Of course I can call a method with String as a param but I need/want to pass Event subclass in xml. How to achieve that?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source