Wun
Wun

Reputation: 6381

How to set LiveData<List<customType>> to MutableLiveData<List<customType>>?

I am developing in Android, and try to get the LiveData<List<customType>> via following function.

private fun getDataList(): LiveData<List<customType>> {
        return room.getData()
    }

And I create a parameter like the following:

private var customLiveData = MutableLiveData<List<customType>>()

How to set the getDataList() to customLiveData

Thanks in advance.

Upvotes: 0

Views: 111

Answers (1)

Santanu Sur
Santanu Sur

Reputation: 11477

LiveData<T> cannot be set directly into MutableLiveData<T>. However, you can use the value property to set the value of liveData to mutableLiveData, like,

 customLiveData.value = getDataList().value

Upvotes: 1

Related Questions