Android 我正在尝试从Firestore获取多值查询,我做得对吗?

Android 我正在尝试从Firestore获取多值查询,我做得对吗?,android,google-cloud-firestore,Android,Google Cloud Firestore,我使用hashmap从用户想要的过滤数据片段中获取数据 我想构建一个动态Firestore获取查询,但我 不确定这是否是正确的方法 我不熟悉firestore查询,但我尝试通过使用foreach将变量存储到查询中来建立动态查询,在代码解释中我转换了这段代码 Query filterQuery= db.collection("Property"). .whereEqualTo("noBathrooms", "5") .whereEqualTo("noRooms", "2"); 到此为止。 f

我使用hashmap从用户想要的过滤数据片段中获取数据 我想构建一个动态Firestore获取查询,但我 不确定这是否是正确的方法

我不熟悉firestore查询,但我尝试通过使用foreach将变量存储到查询中来建立动态查询,在代码解释中我转换了这段代码

Query filterQuery= db.collection("Property").
 .whereEqualTo("noBathrooms", "5")
 .whereEqualTo("noRooms", "2");
到此为止。

for(Map.Entry<String, Object> entry : list.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue().toString();
        filterQuery=propertyRef.whereEqualTo(key,value);
    }
for(Map.Entry:list.entrySet()){
String key=entry.getKey();
字符串值=entry.getValue().toString();
filterQuery=propertyRef.whereEqualTo(键,值);
}
我在这里设置查询

public void filterData(){

    Query filterQuery =null;
    for(Map.Entry<String, Object> entry : list.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue().toString();
        Log.i(key,value);
        filterQuery=propertyRef.whereEqualTo(key,value);
    }
    dataFetch(filterQuery,R.id.rentRV);
}
public void filterData(){
Query filterQuery=null;
对于(Map.Entry:list.entrySet()){
String key=entry.getKey();
字符串值=entry.getValue().toString();
Log.i(键、值);
filterQuery=propertyRef.whereEqualTo(键,值);
}
数据提取(filterQuery,R.id.rentRV);
}
我在这里建造它

private void dataFetch(Query query,int rvView){

  FirestoreRecyclerOptions<Property> options = new 
  FirestoreRecyclerOptions.Builder<Property>()
        .setQuery(query, Property.class)
        .build();

  mAdapter = new DiscoverAdapter(options);
  RecyclerView recyclerView = root.findViewById(rvView);
  recyclerView.setHasFixedSize(true);
  recyclerView.setLayoutManager(new 
  LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false));
  recyclerView.setAdapter(mAdapter);
  mAdapter.startListening();
  mAdapter.setOnItemClickListener((documentSnapshot, position) -> {
    Property property = documentSnapshot.toObject(Property.class);
    String id = documentSnapshot.getId();
    Bundle mBundle = new Bundle();
    mBundle.putString("id", id);
    Toast.makeText(getContext(), id, Toast.LENGTH_SHORT).show();

});
}
private void dataFetch(查询,int-rvView){
FirestoreRecyclerOptions选项=新建
FirestoreRecyclerOptions.Builder()
.setQuery(查询,属性.class)
.build();
mAdapter=新发现适配器(选项);
RecycleView RecycleView=root.findViewById(rvView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(新建
LinearLayoutManager(getContext(),LinearLayoutManager.HORIZONTAL,false));
recyclerView.setAdapter(mAdapter);
mAdapter.startListening();
mAdapter.setOnItemClickListener((文档快照,位置)->{
Property=documentSnapshot.toObject(Property.class);
String id=documentSnapshot.getId();
Bundle mBundle=新Bundle();
mBundle.putString(“id”,id);
Toast.makeText(getContext(),id,Toast.LENGTH_SHORT).show();
});
}

你最好问谷歌..你最好问谷歌。。