问题描述
因此,无论何时将应用程序安装在设备上,它都会运行一个工作程序来进行数据库的初始植入。这样做很好,但是播种完成后,应该检索值的livedata查询不会更新。只有在视图模型中更改查询后,它才能正确更改。我不知道为什么。任何建议将不胜感激!
片段
viewmodel.sortedItems.observe(viewLifecycleOwner){
..
// Refreshes recyclerview
}
viewmodel
var searchQuery = mutablelivedata<String>("")
val filtered = Transformations.switchMap(searchQuery){repository.getItems(it)}
val sortedItems = MediatorLiveData<List<Restaurant>>()
init{
sortedItems.addSource(filtered){sortData(it)}
}
存储库
fun getItems(query: String): LiveData<List<Item>> = itemDao.retrieveAll(query)
ItemDao
@Query("SELECT * FROM Item WHERE title LIKE :query || '%'"
fun retrieveAll(query: String): LiveData<List<Item>>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)