mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-22 13:48:29 +00:00
Fix search function not work
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user