1

how to keep button disable any editText Empty ?

i've try with implementation 'androidx.core:core-ktx:1.1.0':

txtEmailOrNoPhone.doOnTextChanged { text, start, count, after ->
            if (text.toString().isEmpty()) {
                buttonLogin.isEnabled = false
            } else {
                txtPassword.doOnTextChanged { text, start, count, after ->
                    buttonLogin.isEnabled = text.toString().isNotEmpty()
                }
            }
        }

but, not work.

because, if i run app (button enable). if i type and delete all (button disable). so, i must type first and delete to (button disable)

i want : if start app

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Afdal
  • 501
  • 9
  • 19
  • The question is not really clear, please try explaining better your problem, maybe posting some screenshots – Luca Murra Feb 06 '20 at 08:48

1 Answers1

2

Since your code inside the doOnTextChanged is not triggered until you type something, your initial state of disabling the button will not work.

For that, just set the button disabled initially in the xml

android:enabled="false"

Archie.bpgc
  • 23,812
  • 38
  • 150
  • 226