EditText Hex mode on Android

I need to enter only hexadecimal characters to an editText in Android, but these characters must be entered in pairs, after each pair you should automatically insert a space and then the next pair and so on, someone could tell me how to do it

This would set your EditText to only receive the characters set in android:digits .

But what you want is that you also add a space every two characters, to do this you can define a InputFilter , where you will evaluate if the character is alphanumeric and using a REGEX if it is included in the characters "0123456789ABCDEF" , when detecting that you have written 2 allowed characters, you will add a space for the following: