Bind Observable for Android Activity / Fragment / View Lifecycles
Please type it in your build.gradle file.
repositories {
jcenter()
}
dependencies {
compile 'moe.pine.rxbindroid:rxbindroid:0.1.3'
compile 'moe.pine.rxbindroid:rxbindroid-kotlin:0.1.3' // for Kotlin
}
import moe.pine.rx.bindroid.RxBindroid;
final TextView view = (TextView)this.findViewById(R.id.text_view_hello);
Observable<String> observable = Observable.just("Hello");
// It will call `unsubscribe` automatically.
RxBindroid.bindView(view, observable).subscribe(new Action1<String>() {
@Override
public void call(String s) {
// called by MainThread
view.setText(s);
}
});
import moe.pine.rx.bindroid.bindView
val view = this.findViewById(R.id.text_view_hello) as TextView
val observable = Observable.just("Hello")
// It will call `unsubscribe` automatically.
observable.bindView(view).subscribe { view.text = it }
- RxBindroid.bindActivity
- RxBindroid.bindFragment
- RxBindroid.bindView
- Observable<T>.bindActivity
- Observable<T>.bindFragment
- Observable<T>.bindView
$ ./gradlew clean test
$ ./gradlew clean assemble bintrayUpload
RxBindroid is based on RxAndroid#v0.25.0. Thank you.
Copyright 2015 The RxAndroid authors
Copyright 2016 Pine Mizune
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.