小编use*_*105的帖子

Kotlin扩展函数数据绑定

是否有可能使用数据绑定扩展功能?XML:

<data>
    <import type="my.package.domain.country.model.City.streetName" />

    <variable
        name="city"
        type="my.package.domain.country.model.City" />
</data>

<TextView
    android:id="@+id/city"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@{city.street.streetName()}" />
Run Code Online (Sandbox Code Playgroud)

my.package.domain.country.model.city

data class City(
        val id: String,
        val street: Street
) 

fun City.streetName(): String = street.houseNumber
Run Code Online (Sandbox Code Playgroud)

错误

[kapt]发生异常:android.databinding.tool.util.LoggedErrorException:发现数据绑定错误.****/数据绑定错误****msg:在类my.package.domain.country.model.City中找不到方法streetName()

谢谢 ;)

mvvm kotlin extension-function

19
推荐指数
3
解决办法
2914
查看次数

标签 统计

extension-function ×1

kotlin ×1

mvvm ×1