错误的代码:
import androidx.core.widget.addTextChangedListener
et_input_phone?.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
) {
}
override fun afterTextChanged(s: Editable) {
//这个方法一直无法触发
}
}
}
正确的代码:
et_input_phone?.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
) {
}
override fun afterTextChanged(s: Editable) {
//这里的方法才能正常触发
}
}
)
结论: 两个addTextChangeListener 用串了导致TextWatcher中的方法一直无法触发