1

What is better when need to listen/watch/observe value of edit text

  • using RxBinding (RxTextView.textChanges)
  • using doOnTextChanged ( reviewEditText.doOnTextChanged { _, _, _, _ -> checkButtonState() })

I have a screen with several EditTextViews and want to disable/enable a button based on content of these Views, so what is more efficient to do this?

Ryan M
  • 18,333
  • 31
  • 67
  • 74
Mahmoud Mabrok
  • 1,362
  • 16
  • 24

1 Answers1

0

If you use RxKotlin, I would suggest using RxBinding because it gives you the ability to combine validations in an easy way:

disposable = Observables.combineLatest(
        emailEditTextObservable.map { isEmailValid() }, 
        phoneEditTextObservable.map { isPhoneValid() }) { validEmail, validPhoneNumber ->
        validEmail && validPhoneNumber
    }.subscribe { button.isEnabled = it }
ExpensiveBelly
  • 444
  • 5
  • 8