kotlin - 如何在 kotlin 的布局文件中绑定来自内部数据类的变量?
问题描述
我正在尝试从内部数据类绑定变量的值。但是我无法访问内部数据类中的变量。我已经在内部给出了外部数据类<data> <<data>
。
请在下面找到数据类和 layout.xml 文件。
data class User( val name:String ,val property:List<Property>)
data class Property(val propertyName:String, val owners:List<Owner>)
data class Owner(val ownerName:String)
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
<variable
name="user"
type="com..User" />
</data>
<LinearLayout>
<TextView
android:id="@+id/owner_textview"
[...]
android:text="{}"/>
</<LinearLayout>
</layout>
我希望将所有者的名称绑定在 Textview 中。当我尝试使用 访问时
@{user.property[0].owners[0].ownerName}
,它无法访问。怎么能访问一样?
解决方案
推荐阅读
- c++ - 创建指针会占用大量资源吗?
- python - 通用关系没有反映在 django 的迁移中?
- java - 在 Spring 中覆盖库版本
- c - 关于 sizeof 溢出 size_t 的 C 标准
- excel - 运行时错误,用于电子邮件自动化的 VBA EXCEL
- php - PHP中的Excel数据显示自动显示一组行
- python - 使用Event在线程中循环时如何修复Window对象没有属性_stop_thread?
- openssl - 在 Windows 上构建静态 OpenSSL 库
- python - 使用 NetworkX 查找从一个到另一个的最短和最长权重
- python - 在使用 ProcessPoolExecutor 的脚本文件之间共享变量