question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[TextInputLayout] OnFocusChangeListener is only notified on first gained focus

See original GitHub issue

Description: Settings a OnFocusChangeListener on the TextInputEditText inside the TextInputLayout notifies the listener only the very first time the focus is gained.

Expected behavior: The listener should always fire when focus is gained and lost.

Source code:

textInputEditText.setOnFocusChangeListener { _, hasFocus -> 
  println("only fires on first focus gained")
}

Android API version: 29

Material Library version: 1.2.0-alpha04

Device: Emulator

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
acarlsencommented, Sep 2, 2020

I have the exact same issue, as described by kazougagh. When setting endIconMode programatically its never called again.

4reactions
kazougaghcommented, Aug 13, 2020

Hi @leticiarossi , This issue occurs when you try to set the endIconMode programmatically and not using the xml attributes. Like this:

`

 val inputLayout = findViewById<TextInputLayout>(R.id.text_input_layout)
 inputLayout.editText?.onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->

        // ----------------------------
        // Called on first focus only !
        // ----------------------------

        Log.d(TAG, "inputEditText - hasFocus $hasFocus")
        if (inputLayout.endIconMode == TextInputLayout.END_ICON_NONE) {
            inputLayout.endIconMode = TextInputLayout.END_ICON_CLEAR_TEXT
            inputLayout.setEndIconTintList(ColorStateList.valueOf(getColor(R.color.colorPrimaryDark)))
        }
        
    }`
Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I detect focused EditText in android? - Stack Overflow
You can use View.OnFocusChangeListener to detect if any view (edittext) gained or lost focus. for (EditText view : editList){ view.
Read more >
How To Use On Focus Change to Format Edit Text on Android ...
Hello everyone, this post I will be talking about how to use Android Studio View.OnFocusChangeListener() to make sure users are interacting ...
Read more >
Cannot add OnFocusChangeListener to EditText Wrapped ...
The handler of TextInputLayout responds only to message with what value ... so that the programmer can listen to the focus of the...
Read more >
View.OnFocusChangeListener | Android Developers
Public methods. abstract void, onFocusChange(View v, boolean hasFocus). Called when the focus state of a view has changed.
Read more >
TextInputLayout - Android SDK | Android Developers
Layout which wraps an EditText (or descendant) to show a floating label when the hint is hidden due to the user inputting text....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found