Skip to content

Repository files navigation

RxJava2ExampleKT

implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.9'
  • Example 1
var str =StringBuilder()
val observaBLE =Observable.create<String> { emitter ->
str.append("2. Value Default").append("\n")
setView()
emitter.onNext("Hello Zein")
// emitter.onNext(null); // contoh error
emitter.onComplete()
}
val obserVER:Observer<String> =object:Observer<String> {
overridefunonSubscribe(d:Disposable) {
str.append("1. Loading onSubscribe").append("\n")
setView()
}
overridefunonNext(s:String) {
str.append("3. onNext ").append(s).append("\n")
setView()
}
overridefunonError(e:Throwable) {
str.append("3. onError ").append(e.message).append("\n")
setView()
}
overridefunonComplete() {
str.append("4. Loading onComplete").append("\n")
setView()
}
}
observaBLE.subscribe(obserVER)
  • Example 2
var str =StringBuilder()
Observable.create<String> { emitter ->
str.append("2. Value Default").append("\n")
setView()
emitter.onNext("Hello Zein")
// emitter.onNext(null); // contoh error
emitter.onComplete()
}.subscribe(object:Observer<String> {
overridefunonSubscribe(d:Disposable) {
str.append("1. Loading onSubscribe").append("\n")
setView()
}
overridefunonNext(s:String) {
str.append("3. onNext ").append(s).append("\n")
setView()
}
overridefunonError(e:Throwable) {
str.append("3. onError ").append(e.message).append("\n")
setView()
}
overridefunonComplete() {
str.append("4. Loading onComplete").append("\n")
setView()
}
})
  • setview();
privatefunsetView() {
var tv:TextView= findViewById(R.id.tv)
tv.text = str.toString()
}
  • Preview


FullCode MainActivity


Copyright 2020 M. Fadli Zein

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages