gpt4 book ai didi

android - 在 android 布局中使用 kotlin 的 Unit(或任何其他对象)类型

转载 作者:行者123 更新时间:2023-12-05 04:09:25 27 4
gpt4 key购买 nike

研究 Kotlin 的 Unit 类型,这是一个 object基本上代表Java的void .

在某些情况下,我想使用 PublishSubject<Unit>onClick数据绑定(bind)基本上只是发出点击信号。 android xml 如下所示:

<android.support.v7.widget.AppCompatButton
android:layout_width="148dp"
android:layout_height="60dp"
android:onClick="@{() -> viewModel.navigateSubject.onNext(Unit)}" />

layout内我正在介绍类型:

<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="viewModel"
type="com.example.TestViewModel"/>
<import type="kotlin.Unit"/>
</data>
[...]

但是用这种方式调用对象类型当然是不可能的,有没有人找到使用Unit的方法?输入 android xml?

最佳答案

您应该能够像在 Java 代码中一样使用 Unit.INSTANCE

关于android - 在 android 布局中使用 kotlin 的 Unit(或任何其他对象)类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45997922/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com