I need to set a button to "visible" or "gone" dynamically as user types on a TextView field. By using the statement below, I have been able to accomplish it when Enter is pressed, but that would be great if the button becomes visible or gone immediately as the user types or deletes the text content. Any suggestion?
binding.textField.setOnEditorActionListener { v, actionId, event ->
if (v.text.toString().trim().isEmpty()){
binding.button.visibility = View.GONE
} else{
binding.button.visibility = View.VISIBLE
}
return@setOnEditorActionListener true
}
Thank you in advance for your attention! Rodrigo Tomaz.
you should add textchangelistner to your editext and hide button on text change