In android studio I want to change the format of entering a int 1000000 in a edit text like 1.000.000 but I can't

Viewed 38

I want user to enter the amount of money so my app do the math I done all the things and it works great even I made the output to show numbers like 1.000.000 with the help of:

public static String splitDigits(float number) {
        return new DecimalFormat("###,###,###").format(number);
    }

But for edit text I don't know how to do it I want to make the number easy to read for the user when entering the number in edit text is there any way to use this method for edit text?

1 Answers

i think what you are looking for is textchangelistener of edittext

 edittext.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            edittext.setText(splitDigit(Float.parseFloat(charSequence.toString())));
        }

        @Override
        public void afterTextChanged(Editable editable) {

        }
    });
Related