Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Demo that shows how to use RxJava with Android Data Binding ObservableFields

License

NotificationsYou must be signed in to change notification settings

TangoAgency/android-data-binding-rxjava

Repository files navigation

Android Arsenal android-data-binding-rxjavaBuild Status

Simple demo developed with love atTango which demonstrates how to wrap Android DataBinding ObservableField into RxJava's Observable.

With this solution it is possible to register for ObservableField's value changes and use it with RxJava operators.

You can read Medium story which explains this concept -RxJava meets Android Data Binding.

Example code

publicstaticclassMainViewModel {publicObservableField<String>firstName =newObservableField<>();publicObservableField<String>lastName =newObservableField<>();publicObservableField<String>helloText =newObservableField<>();publicObservableBooleanhelloButtonEnabled =newObservableBoolean(false);publicMainViewModel() {Observable.combineLatest(toObservable(firstName),toObservable(lastName), (firstName,lastName) ->StringUtils.isNotNullOrEmpty(firstName) &&StringUtils.isNotNullOrEmpty(lastName))                    .subscribe(result -> {helloButtonEnabled.set(result);if (!result) {helloText.set(StringUtils.EMPTY);                        }                    },Throwable::printStackTrace);        }publicvoidbuttonClicked() {helloText.set(String.format("Hello %s %s !",firstName.get(),lastName.get()));        }}

rxjava-databinding

How it works

You can findtoObservable method implementation inRxUtils.java class.

It uses ObservableField'sOnPropertyChangedCallback and expose property change events to the "RxWorld".

About

Demo that shows how to use RxJava with Android Data Binding ObservableFields

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

Languages


[8]ページ先頭

©2009-2025 Movatter.jp