Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何通过将值设置为变量来更新LiveData_Android_Android Livedata - Fatal编程技术网

Android 如何通过将值设置为变量来更新LiveData

Android 如何通过将值设置为变量来更新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

我有一个变量和一个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 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)
}