https://kotlinlang.org logo
#android
Title
# android
t

TheDukerChip

06/25/2019, 11:13 AM
I'm using this data class to store the form data
Copy code
data class FormData(
    private var _email: String = "",
    private var _password: String = "",
    private var _isAllFieldsValid: Boolean = false
) : BaseObservable() {
    var email: String
        @Bindable get() = _email
        set(value) {
            _email = value
            notifyPropertyChanged(BR.email)
        }

    var password: String
        @Bindable get() = _password
        set(value) {
            _password = value
            notifyPropertyChanged(BR.password)
        }

    // I want this function to be notifed for both email and password changes
    fun onValuesChanged() {
        
    }
}
Is there any way to achieve this rather than callback or observer?
s

shikasd

06/25/2019, 1:09 PM
Kotlin has
observable
property delegate, probably that will work for you
p

Paulius Ruminas

06/25/2019, 1:34 PM
Just call the method in setters
Copy code
var email: String
        @Bindable get() = _email
        set(value) {
            _email = value
            onValuesChanged()
            notifyPropertyChanged(BR.email)
        }

    var password: String
        @Bindable get() = _password
        set(value) {
            _password = value
            onValuesChanged()
            notifyPropertyChanged(BR.password)
        }
☝️ 1
12 Views