-
Notifications
You must be signed in to change notification settings - Fork 119
Open
Description
Describe the bug
Hello, I have a problem with switching keyboard during typing. When I switch input type from InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS to InputType.TYPE_CLASS_NUMBER I am getting an error IndexOutOfBoundsException. I read the knowing issues https://github.com/RedMadRobot/input-mask-android#knownissues and try to specify android:digit but it does not help. Is there any other solution please ?
Expected behaviour
Switch keyboard from text to numeric without clearing edit text (IndexOutOfBoundsException)
Platform information
- OS version: [e.g. Android 10]
- Library version: [e.g. 6.1]
Code:
fun formatter(inputLayout: TextInputLayout) {
with(inputLayout.editText!!) {
val listener = MaskedTextChangedListener("[AA] [00]", this, object : MaskedTextChangedListener.ValueListener {
override fun onTextChanged(maskFilled: Boolean, extractedValue: String, formattedValue: String) {
inputType = if (formattedValue.length >= 2) {
InputType.TYPE_CLASS_NUMBER
} else {
InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
}
}
})
addTextChangedListener(listener)
onFocusChangeListener = listener
}
}
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout"
style="@style/TextInputLayoutStyle"
android:hint="hint"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/textInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
formatter(textInputLayout)