<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sardor Narziyev on Medium]]></title>
        <description><![CDATA[Stories by Sardor Narziyev on Medium]]></description>
        <link>https://medium.com/@Sardorbekcyber?source=rss-2b276bc0447f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*0yT6BTig4BqsiKYKFP95rw.png</url>
            <title>Stories by Sardor Narziyev on Medium</title>
            <link>https://medium.com/@Sardorbekcyber?source=rss-2b276bc0447f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 15:00:27 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@Sardorbekcyber/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[TextChangedListener with debounce]]></title>
            <link>https://medium.com/@Sardorbekcyber/textchangedlistener-with-debounce-4115c7b58dda?source=rss-2b276bc0447f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4115c7b58dda</guid>
            <category><![CDATA[edittext]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[android-edittext]]></category>
            <dc:creator><![CDATA[Sardor Narziyev]]></dc:creator>
            <pubDate>Thu, 07 Oct 2021 18:35:07 GMT</pubDate>
            <atom:updated>2021-10-07T18:45:56.941Z</atom:updated>
            <content:encoded><![CDATA[<p>With pure Kotlin no Coroutines!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*u0kUsFMULWD8O1I_" /><figcaption>Photo by <a href="https://unsplash.com/@boudewijn_huysmans?utm_source=medium&amp;utm_medium=referral">Boudewijn Huysmans</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In many cases where we override Text Watcher or similar method we end up not using all methods offered by an particular API. This leads to unused overidden method decreasing code cleanness. Below we will see how we can avoid this with Kotlin language features and implement simple debounced textChangedListener overriding only it’s one method.</p><p>First let’s take a look default TextWatcher implementation</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/364d927bc786945f3ae18ad29d1e985a/href">https://medium.com/media/364d927bc786945f3ae18ad29d1e985a/href</a></iframe><p>and for Java it will look something like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b4f3afd32d6f10496cff6db7a4c28ad/href">https://medium.com/media/2b4f3afd32d6f10496cff6db7a4c28ad/href</a></iframe><p>As I told before there is a problem with this approach. If you have multiple EditText like widgets in your UI you end up overriding multiple similar method. However I have got a good news for you. There is a simple sollution to this problem.</p><p>Functions are first class citizen in Kotlin and it supports other many <a href="https://kotlinlang.org/docs/lambdas.html">functional programming concepts</a>. In this example we will use high-order functions.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b39af8a0fd01ed6e559208fdea9d30be/href">https://medium.com/media/b39af8a0fd01ed6e559208fdea9d30be/href</a></iframe><p>But Java does not have such a language features so you can implement your own TextWatcher like this.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3094a16faca9451e9df2cdf2d31e79f3/href">https://medium.com/media/3094a16faca9451e9df2cdf2d31e79f3/href</a></iframe><p>You may ask what about debounce you promised us? It is as simple as this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eb1ca46880ca1e62a2e3a2c09b80ba44/href">https://medium.com/media/eb1ca46880ca1e62a2e3a2c09b80ba44/href</a></iframe><p>But you are not limited with only TextWatcher you can take a heavy use of this technique in many other ways. For example your button does an network call which is pretty heavy operation in mobile applications. So you want click to be debounced. You can implement clickWithDebounce like this</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b572f89218579d57cb6c6503b782c472/href">https://medium.com/media/b572f89218579d57cb6c6503b782c472/href</a></iframe><p><em>Voilà! Enjoy Kotlin! Don’t forget to subscribe!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4115c7b58dda" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>