我正在一个项目中工作(使用Android的房间持久性库),我希望通过Google实现最近的Paging Library。我试图在不使用它的情况下接近它,并且一切正常,但是当我尝试通过遵循一些教程来使用它时,我没有收到任何数据。你能帮我吗?我不知道我做错了什么。
NavigationDao :
@Query("SELECT chapters.number, chapter, verses.verse_number, name, text FROM verses INNER JOIN chapters ON chapters.chapter = verses.chapters " +
"INNER JOIN books ON books._id = chapters.books WHERE text LIKE :keywords AND verses.types_of_verse = 1 ORDER BY verses._id")
DataSource.Factory<Integer, SearchReference> getSearchResultPagedList(String keywords);
存储库:
public DataSource.Factory<Integer, SearchReference> getPagedListSearchResult(String keyword){
return mNavigationDao.getSearchResultPagedList(keyword);
}
视图模型:
public LiveData<PagedList<SearchReference>> searchReferencePagedList;
private SearchKeywordRepository mRepository;
public SearchKeywordViewModel(SearchKeywordRepository repository, final String keyword){
this.mRepository = repository;
allSearchReferenceList = new ArrayList<>();
}
public void init(String keyword)
searchReferencePagedList = new LivePagedListBuilder<>(mRepository.getPagedListSearchResult(keyword), 20).build();
}
UI片段
private void observeKeywordQuery(String keywords) {
mViewModel.init(keywords);
mViewModel.searchReferencePagedList.observe(this, searchReferenceList -> {
if (searchReferenceList != null && searchReferenceList.size() > 0) {
mRecyclerAdapter.submitList(searchReferenceList);
} else {
Log.d(LOG_TAG, "No verses retrieved");
}
});
}
答案 0 :(得分:0)
经过多次努力,我找到了解决方案。那是如此直截了当,我感到很惭愧。
要调试,我会直接在View Model中输入字符&#34; deu&#34;。问题是我忘了添加&#39;%&#39;标志。所以,在我输入&#34;%deu%&#34;的那一刻,一切正常,我得到了所有预期的结果。