java - 不存在类型变量 Y 的实例,因此 Calendar 符合 LiveData<Y>

标签 java android transformation android-livedata switchmap

我想要我的LiveData<Calendar>每次更改实例ListAlarms改变。我有以下代码:

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/

相关文章:

java - Spinner onItemSelectedListener 不起作用?

android - 从 fragment 设置 WebView 的页面标题

iOS:关于 GLKMatrix4MakeLookAt 结果中的相机信息的问题

c# - 在 C# 中使用矩阵标准化变换后的图像

java - 查找在 ListView 中单击了哪一行

java - 结合读取和解析 text.txt

java - Android Wear 上的奇怪渲染问题

java - 在 Grizzly 中配置 session cookie 名称

android - SHA1 证书指纹

python - Matplotlib 自定义投影 : How to transform points