Skip to content

Instantly share code, notes, and snippets.

@weverb2
Created January 22, 2019 01:06
Show Gist options
  • Save weverb2/500feb2af846c9ec2c57ea3694a70ad8 to your computer and use it in GitHub Desktop.
Save weverb2/500feb2af846c9ec2c57ea3694a70ad8 to your computer and use it in GitHub Desktop.
class MainViewModel : ViewModel() {
private val _isFormValid = MutableLiveData<Boolean>()
val isFormValid: LiveData<Boolean>
get() = _isFormValid
var username = ""
set(value) {
field = value
validateForm()
}
var password = ""
set(value) {
field = value
validateForm()
}
private fun validateForm() {
if (username.length > 8 && password.length > 8) {
_isFormValid.postValue(true)
} else {
_isFormValid.postValue(false)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment