如何将值从LiveDataReactiveStreams发布到MutableLiveData?我希望实现双向数据绑定,以切换(视图)并将“选中”值从数据库传递到MutableLiveData和UI。LiveDAtaReactiveStreams只返回不变的LiveData。
//ViewModel
public final MutableLiveData<Boolean> switchChecked = new MutableLiveData<>();
LiveData<Boolean> data = LiveDataReactiveStreams.fromPublisher(/* Flowable from DB */); //??
//xml
<Switch
...
android:checked="@={viewModel.switchChecked}"
/>发布于 2019-06-08 02:01:16
试试MediatorLiveData
//ViewModel
public final MediatorLiveData<Boolean> switchChecked = new MediatorLiveData<>();
public MyViewModel() {
...
switchChecked.addSource(LiveDataReactiveStreams.fromPublisher(/* Flowable from DB */), value -> {
switchChecked.setValue(value);
});
...
}https://stackoverflow.com/questions/56493187
复制相似问题