DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Midhet Sulemani
Midhet Sulemani

Posted on

Realtime TextField updating

I just noticed while making a character count enabled textview that the count is always a few characters behind the actual text.

The problem in this was that the complete string that is entered isn’t updated in the text attributed of your text field until it returns true from the change characters in range function in its lifecycle.

The value of currentText in this function will give you the updated value or the complete string you’ve entered.

Update: The string gives you the latest character you have entered or deleted, if you want the updated text after each character is updated or deleted, your function will look something like this:

This removes the backspaced string from your currentText as well as adds it if you have typed it in.

Hope this helped you :)

Top comments (0)

Regex for lazy developers

regex for lazy devs

You know who you are. Sorry for the callout πŸ˜†