I use MaskedTextChangedListener to format the phone number, the mask is +7 ([000]) [000] - [00] - [00].
With normal manual text input, everything works fine, but if you use the setTex method, the listener throws an exception
java.lang.IndexOutOfBoundsException: setSpan (17 ... 17) ends beyond length 2
at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1325)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:684)
at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:676)
at android.text.Selection.setSelection(Selection.java:94)
at android.text.Selection.setSelection(Selection.java:78)
at android.text.Selection.setSelection(Selection.java:153)
at android.widget.EditText.setSelection(EditText.java:136)
at com.redmadrobot.inputmask.MaskedTextChangedListener.afterTextChanged(MaskedTextChangedListener.kt:193)
at android.widget.TextView.sendAfterTextChanged(TextView.java:10551)
at android.widget.TextView.setText(TextView.java:6278)
at android.widget.TextView.setText(TextView.java:6097)
at android.widget.EditText.setText(EditText.java:122)
Describe the bug
I use MaskedTextChangedListener to format the phone number, the mask is +7 ([000]) [000] - [00] - [00]. With normal manual text input, everything works fine, but if you use the setTex method, the listener throws an exception
java.lang.IndexOutOfBoundsException: setSpan (17 ... 17) ends beyond length 2 at android.text.SpannableStringBuilder.checkRange(SpannableStringBuilder.java:1325) at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:684) at android.text.SpannableStringBuilder.setSpan(SpannableStringBuilder.java:676) at android.text.Selection.setSelection(Selection.java:94) at android.text.Selection.setSelection(Selection.java:78) at android.text.Selection.setSelection(Selection.java:153) at android.widget.EditText.setSelection(EditText.java:136) at com.redmadrobot.inputmask.MaskedTextChangedListener.afterTextChanged(MaskedTextChangedListener.kt:193) at android.widget.TextView.sendAfterTextChanged(TextView.java:10551) at android.widget.TextView.setText(TextView.java:6278) at android.widget.TextView.setText(TextView.java:6097) at android.widget.EditText.setText(EditText.java:122)