Добавление точек после ввода двух цифр переводит курсор на начало строки. Почему?
на скриншоте (gif) сама проблема:
А это часть кода:
currentField.addTextChangedListener(object : TextWatcher {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun afterTextChanged(s: Editable) {
when (currentField.text.length) {
2 -> {
val curText = currentField.text.toString()
currentField.setText(curText + ".")
}
5 -> {
val curText = currentField.text.toString()
currentField.setText(curText + ".")
}
}
}
})
Ответы (1 шт):
Автор решения: Эникейщик
→ Ссылка
Из-за setText(), оно бросает курсор в начало строки.
Варианты:
вместо setText(curText + ".") использовать append(".")
или к тому что есть добавить
currentField.setSelection(currentField.text.length)
