0
調查Kotlin的Unit
類型,這是一個基本上代表Java的void
的object
類型。在android佈局中使用kotlin的單元(或任何其他對象)類型
在某些情況下,我想在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
類型的方法?