I want my LiveData<Calendar>
instance to change everytime List
of Alarms
change. I have following code:
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;
});
Error I see:
No instance(s) of type variable(s) Y exist so that Calendar conforms
Can somebody help me out here? How can I return new Calendar instance in SwitchMapFunction
?
to LiveData
I think you need use Transformation.map()
function instead of Transformation.switchMap()