Set editText text to upper case on addTextChangedListener making app hang

  android, firebase, kotlin

I want to make upper case even if the user write lowercase in edittext.So I am setting ediText text to upper case on addTextChangedListener as per below.

  editText.addTextChangedListener(object : TextWatcher{
            override fun beforeTextChanged(s : CharSequence?, start : Int, count : Int, after : Int) {
            }

            override fun onTextChanged(s : CharSequence?, start : Int, before : Int, count : Int) {
                    editText.setText(s.toString().toUpperCase())
            }

            override fun afterTextChanged(s : Editable?) {

            }
    })

But doing this when I type somthing in editText,app is hanging and I have to kill the app and restart it again.

Source: Android Questions

LEAVE A COMMENT