Is there a way I can group characters from a EditText in blocks while the user is typing? Exemple: 1234
4567
7890
and so on?
I have an edit text that support numeric numbers and has 16 char length and I would like to group them in separated blocks for a better visibility.
Use a
TextListener
, parse your input using something likeArrays.toString(bitstream.split("(?<=\\G.{4})")))
which return an array and then set it to yourEditText
.Example:
If you want to just group visually the numbers, but you don't want to alter the value of the
EditText
adding spaces, you can use this Span approach:where the
SpaceSpan
class looks like this:A full working example is available here.
Add space for every 4 digits.Use the following code.
You can use a TextWatcher. For example: