我正在DAO类中使用这种方法来访问数据库中的数据:
"我是这样调用它的:"
我接着这样观察这个值:
我的问题是,无论我做什么,观察者始终返回null,即使数据库中有与查询匹配的数据。我也尝试过只使用“select * from location_search_results”以确定是否存在searchQuery参数的问题,但结果仍然是null。
这是数据库的样子: 我对Room和SQLite都很陌生,所以非常感谢任何帮助。谢谢。
@Query("select * from location_search_results WHERE searchQuery = :query")
fun searchForLocation(query: String): LiveData<LocationSearchResponse>
"我是这样调用它的:"
locationResponse = locationResponseDao.searchForLocation(query)
Log.d("db", locationResponse.value.toString())
我接着这样观察这个值:
fun bindUI() = launch {
val locationResults = locationViewModel.locationResponse
val owner = viewLifecycleOwner
locationResults.observe(owner, Observer {
if (it == null) return@Observer
initRecyclerView(it.features.toLocationSearchResultListItem())
})
}
我的问题是,无论我做什么,观察者始终返回null,即使数据库中有与查询匹配的数据。我也尝试过只使用“select * from location_search_results”以确定是否存在searchQuery参数的问题,但结果仍然是null。
这是数据库的样子: 我对Room和SQLite都很陌生,所以非常感谢任何帮助。谢谢。
locationResponse.value.
嗯,不要这样调用它,使用observe
。 - undefined