The FormatWatcher library provides a simple and easy-to-use way to apply predefined formatting to user input for Android EditText. The formatter is separator sensitive, meaning if a separator is entered manually, the format will not be applied again.
To install the library use Gradle:
repositories {
mavenCentral()
}
dependencies {
implementation 'io.github.ihermandev:format-watcher:1.0.1'
}
Simply create a new instance of the FormatWatcher
and set it as the TextWatcher
interface for
the EditText
.
val formatter = FormatWatcher("###-##-####", '#')
editText.addTextChangedListener(formatter)
The first argument passed to the FormatWatcher
constructor is the format string to be applied to the
text, the second argument is the character to be used as a placeholder in the format string.
In order to obtain the formatted or raw input String
you can call currentInput
and rawInput
accordingly
via FormatWatcher
instance.
formatter.currentInput
formatter.rawInput
You can customize the behavior of the FormatWatcher class by changing the format string, and the placeholder character to match your specific requirements.
If you find any bugs or have any suggestions for improvements, please open an issue or create a pull request on the GitHub repository
text_watcher_demo_v1_0_1.mp4
This library is released under the Apache 2.0 license. See the LICENSE file for more information.