RxView.clicks(activityNewsButton)
.throttleLast(1000,TimeUnit.MICROSECONDS)
.subscribe(new Action1<Void>() {
@Override
public void call(Void aVoid) {
System.out.println("click");
}
});
经过调试,这样子还是会输出很多个click,好像并没有成功防抖动,为什么
还有compoundbutton也不能实现这个功能
RxCompoundButton.checkedChanges(schoolBusSwitchButton)
.throttleLast(1000, TimeUnit.MICROSECONDS)
.subscribe(new Action1<Boolean>() {
@Override
public void call(Boolean aBoolean) {
System.out.println("switch");
}
});
throttleFirst
The time unit is wrong, 1000 microseconds = 1 millisecond = 0.001 seconds
This time has no anti-shake effect at all
The original intention should be 1000 milliseconds, which is 1 second
The unit conversion is as follows
In addition, both
throttleFirst() and throttleLast() can have an anti-shake effect
The effects are slightly different
throttleFirst() only takes the first time when clicked continuously, and subsequent clicks are ignored
throttleLast() only takes the last one when clicked continuously Once, previous clicks are ignored