0

I have an edit text in an application that receives inputs of numbers. How can I change the space between the numbers so they can be far apart?

Also is it possible to have an input the looks like: 1174 4453 3456 3456 where the space between the numbers come after a specific number of inputs?

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
Lekan
  • 115
  • 1
  • 6

2 Answers2

0

Try android:letterSpacing="0.50"

0

You can use TextWatcher:

editText.addTextChangedListener(new TextWatcher() {
    private static final char spc = ' ';

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {}

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {}

    @Override
    public void afterTextChanged(Editable s) {

        if (s.length() > 0 && (s.length() % 5) == 0) {
            final char c = s.charAt(s.length() - 1);
            if (spc == c) {
                s.delete(s.length() - 1, s.length());
            }
        }

        if (s.length() > 0 && (s.length() % 5) == 0) {
            char c = s.charAt(s.length() - 1);
            if (Character.isDigit(c) && TextUtils.split(s.toString(), String.valueOf(spc)).length <= 3) {
                s.insert(s.length() - 1, String.valueOf(spc));
            }
        }
    }
}); 

For space betwin character you can use android:letterSpacing In xml file