Introducing RxBinding in Android

To aid us Android developers, Jake Wharton created the RxBinding library, which helps you get Android events in a reactive way. You can find them at https://github.com/JakeWharton/RxBinding. Let's get started by adding it to the project.

Add the following dependency to the app level build.gradle file:

    implementation 'com.jakewharton.rxbinding2:rxbinding-kotlin:2.0.0' 

Then we can replace onClick inside ToDoViewHolder with the following line of code:

    itemView.clicks() 
    .subscribeBy { 
       onClickTodoSubject.onNext(Pair(itemView,todoItem)) 
    }

It's that easy. However, you're probably thinking, what's the benefit of making them reactive? The implementation here was simple enough, but think of a situation where you've ...

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.