我使用的是Android上架构组件的LiveData和ViewModel。
这是我的存储库类-
class DataRepository {
var imagePath : String = ""
}
这是我的ViewModel,我想从中获取
图像路径
更新存储库中的值后从存储库中删除-
class DataViewModel : ViewModel() {
internal lateinit var imagePath : MutableLiveData<String>
imagePath.value = DataRepository().imagePath
}
问题是
图像路径
在DataRepository中,类型为
一串
DataViewModel中的imagePath为
可变LiveData
.
如何将存储库中的imagePath值分配给ViewModel中的值?我需要做任何类型的铸造吗?