我可以通過RecyclerView
從Firebase到應用程序檢索數據。但是當我試圖添加搜索視圖它不工作。Android搜索查看Firebase RecyclerView未顯示數據
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_search, menu);
final SearchView searchView =(SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menusearch));
SearchManager searchManager =(SearchManager) getSystemService(SEARCH_SERVICE); searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName());
//searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
//SearchText.setText(newText);
Query Q = mDatabase.child("Recipees").orderByChild("cusine").startAt(newText).endAt("");
FirebaseRecyclerAdapter<ImageRetrieve, BlogViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<ImageRetrieve, BlogViewHolder>(
ImageRetrieve.class,
R.layout.recipe_row,
BlogViewHolder.class,
Q
) {
@Override
protected void populateViewHolder(BlogViewHolder viewHolder, ImageRetrieve model, int position) {
viewHolder.setCusine(model.getCusine());
viewHolder.setCatagory(model.getCatagory());
viewHolder.setRecipe(model.getRecipe());
viewHolder.setUrl(getApplicationContext(), model.getUrl());
}
};
mRecipeList.setAdapter(firebaseRecyclerAdapter);
return false;
}
});
return true;
}
是firebase查詢返回給你的一些? –
關於搜索什麼都沒有,我可以在回收視圖中檢索相同的數據 –
因此,這意味着查詢有錯誤:試試這個:mDatabase.child(「Recipees」)。orderByChild(「cusine」)。equalTo(newText); –