[英]how does debounce without using rxjava
You can make a function with handler.postDelay()
and runnable
, something like this:您可以使用 handler.postDelay
handler.postDelay()
和runnable
制作 function ,如下所示:
private fun debounce(yourParams: Any, delayMillis: Long) {
handler.removeCallbacks(runnable)
runnable = Runnable {
// Your code here.
}
handler.postDelayed(runnable, delayMillis)
}
I've seen an implementation where you create a static variable and set it to true when clicked and then to false when done, because it is static, it disables all the views that use this type of onClick
listener.我见过一个实现,您创建一个 static 变量并在单击时将其设置为 true,然后在完成时将其设置为 false,因为它是 static,它会禁用所有使用此类
onClick
侦听器的视图。
However, part of the debouncing in RxJava is time related, so i guess you could also add a timer.然而,RxJava 中的部分去抖动是与时间相关的,所以我想你也可以添加一个计时器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.