Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching keyboards in mask #119

Open
anonyimek opened this issue Apr 2, 2022 · 1 comment
Open

Switching keyboards in mask #119

anonyimek opened this issue Apr 2, 2022 · 1 comment

Comments

@anonyimek
Copy link

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)

@taflanidi
Copy link
Collaborator

Hey @anonyimek
Thanks for the heads up, I'll take a look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants