Android 如何通过将值设置为变量来更新LiveData
我有一个变量和一个LiveData,我想在为变量设置值时更新LiveDataAndroid 如何通过将值设置为变量来更新LiveData,android,android-livedata,Android,Android Livedata,我有一个变量和一个LiveData,我想在为变量设置值时更新LiveData var trigger = "" val updateValue: LiveData<Value> = service.getValue(trigger) // when set the value1 to trigger, the updateValue need to update the value. var trigger = "value1" val up
var trigger = ""
val updateValue: LiveData<Value> = service.getValue(trigger)
// when set the value1 to trigger, the updateValue need to update the value.
var trigger = "value1"
val updateValue: LiveData<Value> = service.getValue("value1")
var trigger=“”
val updateValue:LiveData=service.getValue(触发器)
//将value1设置为trigger时,updateValue需要更新该值。
var trigger=“value1”
val updateValue:LiveData=service.getValue(“value1”)
使用开关映射
:
var trigger = MutableLiveData<String>()
val updateValue: LiveData<Value> = Transformations.switchMap(trigger) {
service.getValue(it)
}
使用
开关映射
:
var trigger = MutableLiveData<String>()
val updateValue: LiveData<Value> = Transformations.switchMap(trigger) {
service.getValue(it)
}