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

MDC-101: Wrong method to read the input character #68

Open
TonyGuyot opened this issue Feb 27, 2021 · 0 comments
Open

MDC-101: Wrong method to read the input character #68

TonyGuyot opened this issue Feb 27, 2021 · 0 comments

Comments

@TonyGuyot
Copy link

The MDC-101 Codelab is using the setOnKeyListener method to detect the characters typed into the password text field. That method does not work with a soft input keyboard (what one mostly used on an Android device) but only with a hardware keyboard.

The right solution is to use a TextWatcher like that:

        // Clear the error once more than 8 characters are typed.
        val watcher = 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?) {
                if (isPasswordValid(password_edit_text.text)) {
                    // Clear the error.
                    password_text_input.error = null
                }
            }
        }
        view.password_edit_text.addTextChangedListener(watcher)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant