我想要我的LiveData<Calendar>
每次更改实例List
的Alarms
改变。我有以下代码:
private LiveData<Calendar> nextAlarm;
public MyViewModel(@NonNull Application app) {
nextAlarm = Transformations.switchMap(alarmRepo.getAlarms(), alarms -> {
Calendar nearest = null;
// ... some necessary computation here (iterating through alarms):
// foreach alarms, find nearest one, create new Calendar according to day and time saved in database
return nearest;
});
我看到的错误:
No instance(s) of type variable(s) Y exist so that Calendar conforms
有人可以帮我吗?如何在SwitchMapFunction
中返回新的日历实例?
to LiveData
最佳答案
我认为你需要使用 Transformation.map()
函数而不是 Transformation.switchMap()
关于java - 不存在类型变量 Y 的实例,因此 Calendar 符合 LiveData<Y>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56215415/