我希望我的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;
});
我看到的错误:
不存在类型变量 Y 的实例,因此 Calendar 符合
有人可以帮我吗?如何返回新的日历实例SwitchMapFunction
?
到 LiveData