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");
}
});
PHP中文网2017-04-17 17:53:22
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
TimeUnit{
NANOSECONDS,// 纳秒=0.000000001秒
MICROSECONDS,//微妙=0.000001秒
MILLISECONDS,//毫秒=0.001秒
SECONDS,//秒
MINUTES,//分钟
HOURS,//小时
DAYS//天
}
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