如何通过在Android中应用多个查询来过滤Firebase数据结果? [英] How to filter firebase data results by applying multiple Query in Android?

查看:229
本文介绍了如何通过在Android中应用多个查询来过滤Firebase数据结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想显示城市=Varanasi和gender =男性,工资在5000到15000之间。
在这种情况下,必须显示所示工作人员的姓名。
什么查询必须被应用,应该如何实现?首先,我认为你需要保存工资与双重价值,而不是字符串。

您需要在worker节点上引用,然后添加一个侦听器并迭代这些值。你也需要一个工人类来获取数据。

  yourReference.orderByChild(city)。equalTo(Varanasi)。addListenerForSingleValueEvent(){

@Override
public void onDataChange(Datasnapshot data){
for(Datasnapshot d:data.getChildren()){
yourClass work = d.getValue(yourClass.class);
if(work.getGender()。equals(Male){
double salary = work.getSalary();
if(salary> 5000&& salary< 15000 ){
//将工作人员保存到列表中。
}
}
}
}
}
}


I want to display all the worker names whose city="Varanasi" and gender="Male" and salary is between 5000 to 15000 in a Recycler View. In this case the name of the shown worker must be displayed. What query must be applied and how should it be achieved?

解决方案

First, I think you need save the salary with double value, not string.

You need your reference at worker node, then add a listener and iterate the values. Also you need a worker class to obtain the data.

yourReference.orderByChild("city").equalTo("Varanasi").addListenerForSingleValueEvent(){

    @Override
    public void onDataChange(Datasnapshot data){
       for(Datasnapshot d: data.getChildren()){
         yourClass work = d.getValue(yourClass.class);
         if(work.getGender().equals("Male"){
            double salary = work.getSalary();
           if(salary  > 5000 && salary < 15000){
                 //save the worker into a list. 
            }
         } 
       }
      }
    }
}

这篇关于如何通过在Android中应用多个查询来过滤Firebase数据结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆