具有初始值的MutableLiveData [英] MutableLiveData with initial value

查看:1108
本文介绍了具有初始值的MutableLiveData的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用初始值初始化 MutableLiveData ? 我正在寻找类似的东西:

How I can initialize MutableLiveData with initial value? I'm looking for something like:

val text = MutableLiveData<String>("initial value")

推荐答案

MutableLiveData已更新,现在有一个接受初始值的构造函数:)

MutableLiveData has been updated and now it has a constructor that accepts an initial value :)

据我所见,此版本开始提供了构造函数:

From what I can see, the constructor is available starting from this version:

implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0-alpha01'

可惜他们还没有更新MediatorLiveData来反映这一点.

It's a shame they haven't updated MediatorLiveData to reflect that, though.

2.1.0终于稳定了,所以现在您实际上可以在文档中看到新的构造函数.

2.1.0 is finally stable, so now you can actually see the new constructor in the documentation.

这篇关于具有初始值的MutableLiveData的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆