I have a range slider for prices of food , and based on the min and max of the slider , I want to display the foods which are in this range.
Slider code
multiSlider.setOnThumbValueChangeListener(new MultiSlider.SimpleChangeListener() {
@Override
public void onValueChanged(MultiSlider multiSlider, MultiSlider.Thumb thumb, int thumbIndex, int value) {
if (thumbIndex == 0) {
min = String.valueOf(value);
min1.setText(min);
} else {
max = String.valueOf(value);
max1.setText(max);
}
}
});
alertD.setPositiveButton("Done", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
SearchPrice(min, max);
}
});
Query Code
private void SearchPrice(String min, String max) {
Query searchByName = foodList.orderByChild("price").startAt(min).endAt(max);
FirebaseRecyclerOptions<Food> foodOptions = new FirebaseRecyclerOptions.Builder<Food>().setQuery(searchByName, Food.class).build();
Searchadapter = new FirebaseRecyclerAdapter<Food, FoodViewHolder>(foodOptions) {
@Override
protected void onBindViewHolder(@NonNull FoodViewHolder viewHolder, int position, @NonNull Food model) {
viewHolder.food_name.setText(model.getName());
viewHolder.food_price.setText(model.getPrice());
Structure
I tried using the startAt and endAt , but its displaying food with prices outside of the range.Any help on this please ? Is there another way of doing this type of query?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…