Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
191 views
in Technique[技术] by (71.8m points)

android - Querying by range in firebase

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

enter image description here

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...