时间:2021-07-01 10:21:17 帮助过:9人阅读
分别进行订阅
- private Observable
contactObserver() { - Observable
obser1 = Observable.just(1, 2, 3); - Observable
obser2 = Observable.just(4, 5, 6); - Observable
obser3 = Observable.just(7, 8, 9); - return Observable.concat(obser1, obser2, obser3);
- }
- private Observable
conuntObserver() { - return Observable.just(1, 2, 3).count();
- }
运行结果如下
- mLButton.setText("contact");
- mLButton.setOnClickListener(e -> contactObserver().subscribe(i -> log("contact:" + i)));
- mRButton.setText("conunt");
- mRButton.setOnClickListener(e -> conuntObserver().subscribe(i -> log("conunt:" + i)));
分别进行订阅
- private Observable
reduceObserver() { - return Observable.from(list).reduce((x, y) -> x * y);
- }
- private Observable> collectObserver() {
- return Observable.from(list).collect(() -> new ArrayList<>(), (integers, integer) -> integers.add(integer));
- }
运行结果如下
- mLButton.setText("reduce");
- mLButton.setOnClickListener(e -> reduceObserver().subscribe(i -> log("reduce:" + i)));
- mRButton.setText("collect");
- mRButton.setOnClickListener(e -> collectObserver().subscribe(i -> log("collect:" + i)));
http://www.bkjia.com/PHPjc/1077805.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1077805.htmlTechArticleRxJava操作符(八)Aggregate 在这篇文章里我们来了解一下Rxjava的聚合操作符。 一、Contact Contact操作符将多个Observable结合成一个Observable并发射...