Package icyllis.modernui.lifecycle

# Class MutableLiveData<T>

java.lang.Object
icyllis.modernui.lifecycle.LiveData<T>
icyllis.modernui.lifecycle.MutableLiveData<T>

Type Parameters:
  `T` - The type of data hold by this instance

Direct Known Subclasses:
  `MediatorLiveData`

public class MutableLiveData<T> extends LiveData<T>
`LiveData` which publicly exposes `setValue(T)` and `postValue(T)` method.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MutableLiveData()`
  Creates a MutableLiveData with no value assigned to it.
  `MutableLiveData(T value)`
  Creates a MutableLiveData initialized with the given `value`.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `postValue(T value)`
  Posts a task to a main thread to set the given value.
  `void`
  `setValue(T value)`
  Sets the value.

  ### Methods inherited from class icyllis.modernui.lifecycle.LiveData

  `getValue, hasActiveObservers, hasObservers, observe, observeForever, onActive, onInactive, removeObserver, removeObservers`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### MutableLiveData

    public MutableLiveData(T value)
    Creates a MutableLiveData initialized with the given `value`.
    Parameters:
      `value` - initial value

  - ### MutableLiveData

    public MutableLiveData()
    Creates a MutableLiveData with no value assigned to it.

- ## Method Details

  - ### postValue

    public void postValue(T value)
    Description copied from class: `LiveData`
    Posts a task to a main thread to set the given value. So if you have a following code executed in the main thread:

         liveData.postValue("a");
         liveData.setValue("b");

    The value "b" would be set at first and later the main thread would override it with the value "a".

    If you called this method multiple times before a main thread executed a posted task, only the last value would be dispatched.

    Overrides:
      `postValue` in class `LiveData<T>`
    Parameters:
      `value` - The new value

  - ### setValue

    public void setValue(T value)
    Description copied from class: `LiveData`
    Sets the value. If there are active observers, the value will be dispatched to them.

    This method must be called from the main thread. If you need set a value from a background thread, you can use `LiveData.postValue(Object)`

    Overrides:
      `setValue` in class `LiveData<T>`
    Parameters:
      `value` - The new value