Android-类型与LiveData变量不匹配

问题描述

我的视图模型中有以下内容:

// hold the list of comments of a Post
private val _commentsOfPost = MutableLiveData<PagedList<Comment>>()

val commentsOfPost : LiveData<PagedList<Comment>> = _commentsOfPost

fun getCommentsOfPost(postId: Long){
     _commentsOfPost.value = commentRepository.getCommentsOfPost(postId)   // <--- TYPE MISMATCH
}

因此,发生的事情是,每当Fragment调用getCommentsOfPost()时,它就会检索属于其ID指定的PagedList的{​​{1}}实例中的Comment

但是Android告诉我有关Post的信息(请参见上面的代码片段中的箭头):

Type mismatch

为了完整起见,这是Required: PagedList<Comment>? Found: LiveData<PagedList<Comment>> 界面:

getCommentsOfPost()

如何更改它以使此错误消失?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)