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;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
recyclerView = (RecyclerView) findViewById(R.id.recyler_food);
|
setTitle(categoryName);
|
||||||
recyclerView.setHasFixedSize(true);
|
|
||||||
layoutManager = new LinearLayoutManager(this);
|
|
||||||
recyclerView.setLayoutManager(layoutManager);
|
|
||||||
|
|
||||||
//Search
|
//Search
|
||||||
materialSearchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
|
materialSearchBar = (MaterialSearchBar) findViewById(R.id.searchBar);
|
||||||
materialSearchBar.setHint("Enter your food");
|
materialSearchBar.setHint("Enter your food");
|
||||||
loadSuggest();
|
loadSuggest();
|
||||||
materialSearchBar.setLastSuggestions(suggestList);
|
|
||||||
materialSearchBar.setCardViewElevation(10);
|
materialSearchBar.setCardViewElevation(10);
|
||||||
materialSearchBar.addTextChangeListener(new TextWatcher() {
|
materialSearchBar.addTextChangeListener(new TextWatcher() {
|
||||||
@Override
|
@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
|
// calling the action bar
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
@@ -207,7 +206,7 @@ public class FoodList extends AppCompatActivity {
|
|||||||
|
|
||||||
private void startSearch(CharSequence text) {
|
private void startSearch(CharSequence text) {
|
||||||
//Create query by name
|
//Create query by name
|
||||||
Query searchByName = foodList.orderByChild("Name").equalTo(text.toString());
|
Query searchByName = foodList.orderByChild("name").equalTo(text.toString());
|
||||||
//Create options with query
|
//Create options with query
|
||||||
FirebaseRecyclerOptions<Food> foodOptions = new FirebaseRecyclerOptions.Builder<Food>()
|
FirebaseRecyclerOptions<Food> foodOptions = new FirebaseRecyclerOptions.Builder<Food>()
|
||||||
.setQuery(searchByName, Food.class)
|
.setQuery(searchByName, Food.class)
|
||||||
@@ -243,7 +242,7 @@ public class FoodList extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void loadSuggest() {
|
private void loadSuggest() {
|
||||||
foodList.orderByChild("MenuId").equalTo(categoryId)
|
foodList.orderByChild("menuId").equalTo(categoryId)
|
||||||
.addValueEventListener(new ValueEventListener() {
|
.addValueEventListener(new ValueEventListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||||
@@ -251,6 +250,8 @@ public class FoodList extends AppCompatActivity {
|
|||||||
Food item = postSnapshot.getValue(Food.class);
|
Food item = postSnapshot.getValue(Food.class);
|
||||||
suggestList.add(item.getName());
|
suggestList.add(item.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
materialSearchBar.setLastSuggestions(suggestList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user