Fix search function not work

This commit is contained in:
phanhuuloi27
2022-07-01 19:57:43 +07:00
parent 83dfb4bcef
commit 4f9728d2bc
@@ -131,19 +131,13 @@ public class FoodList extends AppCompatActivity {
return;
}
}
}
});
recyclerView = (RecyclerView) findViewById(R.id.recyler_food);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
setTitle(categoryName);
//Search
materialSearchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
materialSearchBar.setHint("Enter your food");
loadSuggest();
materialSearchBar.setLastSuggestions(suggestList);
materialSearchBar.setCardViewElevation(10);
materialSearchBar.addTextChangeListener(new TextWatcher() {
@Override
@@ -189,8 +183,13 @@ public class FoodList extends AppCompatActivity {
}
});
}
});
setTitle(categoryName);
recyclerView = (RecyclerView) findViewById(R.id.recyler_food);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
// calling the action bar
ActionBar actionBar = getSupportActionBar();
@@ -207,7 +206,7 @@ public class FoodList extends AppCompatActivity {
private void startSearch(CharSequence text) {
//Create query by name
Query searchByName = foodList.orderByChild("Name").equalTo(text.toString());
Query searchByName = foodList.orderByChild("name").equalTo(text.toString());
//Create options with query
FirebaseRecyclerOptions<Food> foodOptions = new FirebaseRecyclerOptions.Builder<Food>()
.setQuery(searchByName, Food.class)
@@ -243,7 +242,7 @@ public class FoodList extends AppCompatActivity {
}
private void loadSuggest() {
foodList.orderByChild("MenuId").equalTo(categoryId)
foodList.orderByChild("menuId").equalTo(categoryId)
.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
@@ -251,6 +250,8 @@ public class FoodList extends AppCompatActivity {
Food item = postSnapshot.getValue(Food.class);
suggestList.add(item.getName());
}
materialSearchBar.setLastSuggestions(suggestList);
}
@Override