Skip to content

Instantly share code, notes, and snippets.

@JoseAlcerreca
Created May 11, 2021 11:55
Show Gist options
  • Save JoseAlcerreca/7546c8b75273ae3dc4400c8492ee4460 to your computer and use it in GitHub Desktop.
Save JoseAlcerreca/7546c8b75273ae3dc4400c8492ee4460 to your computer and use it in GitHub Desktop.
val liveData1: LiveData<Int> = ...
val liveData2: LiveData<Int> = ...
val result = MediatorLiveData<Int>()
result.addSource(liveData1) { value ->
result.setValue(liveData1.value ?: 0 + (liveData2.value ?: 0))
}
result.addSource(liveData2) { value ->
result.setValue(liveData1.value ?: 0 + (liveData2.value ?: 0))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment