Skip to content

LiveDataExtensions

BirjuVachhani edited this page Feb 1, 2019 · 4 revisions

Examples

Observe

   liveData.watch {
       // All you do in your code is observe
   }

Immutability

    liveData.immutable() // converts a MutableLiveData to LiveData
    // Throws an exception if it is not convertible

Initialization

    val liveData = MutableLiveData<String>().initWith("Default_text")

Notify Observers

    userListLiveData.value?.add(User("Birju"))
    userListLiveData.notify()

Helpful when you're not changing the value of it but just updating some values in it. e.g. adding an item into list.

For more information, look at the LiveDataExtensions.kt file.