查询集合的多种文档

时间:2020-04-09 08:20:13

标签: android google-cloud-firestore

image of database在firebase firestore中有一个集合,其中有多个文档。我想根据文档中存在的数据字段来检索文档,如何在android中做到这一点。 我已经完成了

firebaseFirestore = FirebaseFirestore.getInstance();
CollectionReference collectionReference = firebaseFirestore.collection("Planes");
Query query = collectionReference.whereEqualTo("starting",startAirport).whereEqualTo("destination",destinationAirport);
 FirestoreRecyclerOptions<Planes> response = new FirestoreRecyclerOptions.Builder<Planes>()
                .setQuery(query, Planes.class)
                .build();
        firestoreRecyclerAdapter= new FirestoreRecyclerAdapter<Planes,PlaneViewHolder>(response) {
            @NonNull
            @Override
            public PlaneViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
              View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.planes_item,parent,false);
                return new PlaneViewHolder(view);
            }

            @Override
            protected void onBindViewHolder(@NonNull PlaneViewHolder holder, int position, @NonNull Planes model) {
                     holder.book.setOnClickListener(new View.OnClickListener() {
                         @Override
                         public void onClick(View v) {
                             DocumentSnapshot snapshot = getSnapshots().getSnapshot(holder.getAdapterPosition());
                             final String DocId= snapshot.getId();
                             Intent intent=new Intent(PlaneRequestActivity.this,UserDetails.class);
                             intent.putExtra("Document",DocId);
                             intent.putExtra("tripId",tripId);
                             startActivity(intent);
                         }
                     });
                             holder.setPlanes(model);


            }
            @Override
            public void onError(@NonNull FirebaseFirestoreException e) {
                super.onError(e);
                Toast.makeText(PlaneRequestActivity.this,"Error:"+e.toString(),Toast.LENGTH_LONG).show();
            }
        };
        plane.setAdapter(firestoreRecyclerAdapter);
    }


它仅适用于第一个文档。它没有找到馆藏的第二个文件

0 个答案:

没有答案