如以下代码所示,我想使用RxAndroid。但是当我运行代码时,我没有收到来自
的任何日志 @Override
public void onNext(String s) {
Log.d(TAG, "Name: " + s);
}
请让我知道如何解决这些问题。
代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Observer<String> animalsObserver = getAnimalsObserver();
getAnimalsObservable()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.filter(new Func1<String, Boolean>() {
@Override
public Boolean call(String s) {
return s.toUpperCase().equals("D");
}
})
.subscribe(animalsObserver);
}
private Observable getAnimalsObservable() {
return Observable.from(Arrays.asList(
new String[] {
"Ant", "Ape",
"Bat", "Bee", "Bear", "Butterfly",
"Cat", "Crab", "Cod",
"Dog", "Dove",
"Fox", "Frog"
}
));
}
private Observer<String> getAnimalsObserver() {
return new Observer<String>() {
@Override
public void onNext(String s) {
Log.d(TAG, "Name: " + s);
}
@Override
public void onError(Throwable e) {
Log.e(TAG, "onError: " + e.getMessage());
}
@Override
public void onCompleted() {
Log.d(TAG, "All items are emitted!");
}
};
}
}