I wanna use RxJava binding APIs for Android UI widgets in my project.

Therefore following the guidance as per this site 'https://github.com/JakeWharton/RxBinding'

但是我无法在我的Kotlin文件中导入任何Android UI小部件. Where as its working fine if I am consuming these widgets in Java File.个 因此,没有找到这个问题的实际情况.

For reference following are the gradle file and class files(both kotlin and java) using in same project

build.gradle

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.0-beta01'
    implementation 'androidx.core:core-ktx:1.2.0-alpha01'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0-alpha4'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0-alpha4'
    implementation 'io.reactivex.rxjava2:rxjava:2.2.8'
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    //RxBinding
    implementation 'com.jakewharton.rxbinding3:rxbinding:3.0.0-alpha2'
}

BindingExample.java class

enter image description here

RxBindingExample.kt class

enter image description here

Have tried exploring this issue on S.O. but questions or solutions are available for previous version of lib 'com.jakewharton.rxbinding2:rxbinding'

推荐答案

Check this reference: https://github.com/JakeWharton/RxBinding/blob/master/rxbinding/src/main/java/com/jakewharton/rxbinding3/widget/TextViewTextChangeEventObservable.kt

根据语言的不同,有不同的使用方法,请注意开头的@file:JvmName("RxTextView").如果您使用的是java,那么RxTextView类是可见的,在kotlin中,您应该使用lib提供的扩展函数,textChangeEvents()就是一个例子.

like that, this will aquire the observable e.g.:

val someTextView = TextView(context)
someTextView.textChangeEvents()

编辑:

似乎我引用的旧类已被删除,下面是另一个:

Kotlin相关问答推荐

Android前台服务 list —Altbeacon

在Kotlin 有更好的结合方式?

Kotlin编译器如何决定是否可以在任何给定点调用Suspend方法?

如何修改muableStateMapOf的值?

如何优雅地声明一个StateFlow?

kotlin短路列表判断吗?

为什么 Kotlin main 函数需要 @JVMStatic 注解?

Ktor 在 Heroku 上的 CORS 问题,但在本地没有

如何从 Period.between() 返回的字符串中提取信息? (Kotlin )

如何将 `throw` 放置在辅助函数中但仍然具有空安全性?

如何在 Kotlin 中不受约束?

Kotlin - 创建指定长度的随机整数的 ArrayList?

Kotlin JS JSON 反序列化

如何将超过 2 个 api 调用的结果与 Coroutines Flow 结合起来?

retrofit 响应代码 405 并带有消息method not allowed here

Kotlin - 覆盖方法中的 IllegalArgumentException

如何在MVVM架构中观察RecyclerView适配器中的LiveData?

Android Studio 和 Kotlin:Unresolved reference: also

在调用Kotlin数据类中的超类构造函数之前访问函数

如何在 IntelliJ IDEA 中禁用粘贴时将 Java 转换为 Kotlin?