【发布时间】:2017-09-01 10:10:07
【问题描述】:
查看 Kotlin 的 Unit 类型,这是一个 object,基本上代表 Java 的 void。
在某些情况下,我想在 onClick 数据绑定中使用 PublishSubject<Unit> 基本上只是发出点击信号。 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>
[...]
但是这样调用对象类型当然是不可能的,有没有人找到在android xml中使用Unit类型的方法?
【问题讨论】:
标签: android kotlin rx-java2 android-databinding