RxView.clicks(rl).map(new Function<Object, Integer>() {
@Override
public Integer apply(Object o) throws Exception {
return 1;
}
}).scan(new BiFunction<Integer, Integer, Integer>() {
@Override
public Integer apply(Integer integer, Integer integer2) throws Exception {
return ++integer;
}
}).sample(3, TimeUnit.SECONDS).subscribe(new Consumer<Integer>() {
@Override
public void accept(Integer integer) throws Exception {
//差值即为点击次数
Log.i("lpc", "" + (integer - defaultVlaue));
//重新赋值,作为下一次的减数
defaultVlaue = integer;
}
});
defaultValue初始值为0