简体   繁体   中英

how does debounce without using rxjava

I want to do a thing similar to Debounce in Rxjava, but I don't use rxjava as well as using the other librarys. Everyone can suggest for me some ways of doing this.

You can make a function with handler.postDelay() and runnable , something like this:

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.

However, part of the debouncing in RxJava is time related, so i guess you could also add a timer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM