2

Is there a way, perhaps using RxBinding, to bind an Observable<String> to a TextView object such that its .text property is kept up to date with the Observable? Obviously, you could subscribe() and manually update the text field, but a convenience method seems likely. I just can't find it, and the documentation hasn't yielded any answers for me.

A similar convenience method exists in RxSwift (or rather RxCocoa), in case that clarifies what I am asking for; it's called .bindTo() there.

RamwiseMatt
  • 2,717
  • 3
  • 16
  • 22
  • This isn't directly related to your question, but have you seen the Android Data Binding library: https://developer.android.com/topic/libraries/data-binding/index.html? – Tim Pesce Apr 13 '17 at 08:01

1 Answers1

3

Yes methods like this is presented in rx-binding library. For example for TextView RxTextView.text(textView) creates action which can be used as subscriber.

See source code

Usage would be something like this

observable.subscribe(RxTextView.text(textView), Throwable::printStackTrace);

Be careful with memory and read docs:

Warning: The created observable keeps a strong reference to view. Unsubscribe to free this reference.

It is not the same as bindTo magic but doing what you need.

Anton Pogonets
  • 1,162
  • 7
  • 16