java - Kotlin stdlib and Databinding -
is possible use methods kotlin stdlib in xml? example code
<textview android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginbottom="16dp" android:textcolor="#333333" android:text="@{viewmodel.note}" android:visibility="@{viewmodel.note.isnotempty ? view.visible : view.gone}"/> produce compilation error
execution failed task ':app:compiledevdebugjavawithjavac'. java.lang.runtimeexception: found data binding errors. ****/ data binding error ****msg:cannot find method isnotempty() in class java.lang.string file:d:\projects\pushtracker-android\app\src\main\res\layout\fragment_appointment_simple_details.xml loc:104:44 - 104:70 ****\ data binding error ****
it obvious databinding tries find method isnotempty() in java's string can force databinding compiler use kotlin's string?
"kotlin's string" not exist. kotlin's standard library defines extension methods create method you're referring to. since data-binding library needs generate java code cannot find method you're referring to.
in order use method need call using way java call it, static function:
kotlin.text.stringskt.isnotempty(viewmodel.note)
edit: method annotated @inlineonly, method might not exist outside of kotlin code.
Comments
Post a Comment