RxBindingのドキュメントが非常に少ないので、よく使うメソッドを書き残します。
JakeWharton/RxBinding
https://github.com/JakeWharton/RxBinding
Version
implementation "com.jakewharton.rxbinding4:rxbinding:4.0.0"
View
clicks()
viewがタップされたらObservableを流す。
view.clicks().subscribe{}
longClicks()
viewがロングタップされたらObservableを流す。
view.longClicks().subscribe{}
touches()
viewがタップされたらObservableを流す。
view.touches().subscribe{}
RxBindingを使うときの注意点
RxBindingには、以下のような注意書きが書かれている。
Warning:
The created observable keeps a strong reference toview
.
Unsubscribe to free this reference.
つまり、画面を離れるときには、RxBindingに紐づけたViewの参照を切るべきということ。
一方で、issueには以下のように記載されています。
https://github.com/JakeWharton/RxBinding/issues/282
Treat a subscribed RxView.clicks() (or any Observable from this library for that matter) like you would the View reference itself. If you pass it (or subscribe to it) somewhere outside the lifetime of the View, you've just leaked your entire activity.
So if you're just subscribing inside your ViewHolder there's no need to unsubscribe just like there'd be no need to unregister a click listener were you doing it manually.
つまり、該当のViewの外でRxBindingを使用するのであればRxの購読を解除する必要がありますが、Viewの内部で使う限りはとくに購読解除する必要はありません。