Firebase Recyclerview不显示所有项目

时间:2019-01-26 20:07:18

标签: java android database firebase android-recyclerview

在我的应用程序中,我有用户,用户可以为同一商品(同一用户)发送多个buy_request。因此,我在Firebase数据库中创建此结构,并且我的代码在push_ID中搜索,其中get Request_type =“ received”显示用户信息,当我要显示此项目时,我只会得到子项而不是子项for ex(用户A从B两次(两次)检索请求,并且一次形成C,从D 2次检索)正常数字显示的项目数为5,但我只有3个,所有这些项目以及数据库firebase中的最后一个项目的信息

enter image description here

enter code here FirebaseRecyclerOptions<BuyRequest> options = new FirebaseRecyclerOptions.Builder<BuyRequest>()
            .setQuery(mBuyRequast.child(currentUser.getUid()).getRef(),BuyRequest.class).build();

    final FirebaseRecyclerAdapter<BuyRequest,RequastViewHolder> adapter =
            new FirebaseRecyclerAdapter<BuyRequest, RequastViewHolder>(options) {
                @Override
                protected void onBindViewHolder(@NonNull final RequastViewHolder holder, int position, @NonNull BuyRequest model) {

                    listUsersID = getRef(position).getKey();
                    DatabaseReference getTypeRef = getRef(position).child("Request_type").getRef();
                    mBuyRequast.child(currentUser.getUid()).addValueEventListener(new ValueEventListener() {
                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                                  postSnapshot.getKey();
                                for (DataSnapshot sender: postSnapshot.getChildren()) {

                                     if(dataSnapshot.child( postSnapshot.getKey()).child(sender.getKey()).hasChild("Request_type")){

                                         QuantityRequest =dataSnapshot.child( postSnapshot.getKey()).child(sender.getKey()).child("QuantityRequest").getValue().toString();
                                         String type =  dataSnapshot.child( postSnapshot.getKey()).child(sender.getKey()).child("Request_type").getValue().toString();

                                         if (type.equals("received")){
                                             mUsersRef.child(postSnapshot.getKey()).addValueEventListener(new ValueEventListener() {
                                                 @Override
                                                 public void onDataChange(DataSnapshot dataSnapshot) {

                                                     holder.userNameNotify.setText(dataSnapshot.child("UserName").getValue().toString());
                                                     holder.resarvationQuantity.setText(QuantityRequest);
                                                     Picasso.get().load(dataSnapshot.child("Img").getValue().toString()).into(holder.profilImgInNotification);

                                                 }

                                                 @Override
                                                 public void onCancelled(DatabaseError databaseError) {

                                                 }
                                             });
                                         }

                                     }
                                }

                            }
                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {

                        }
                    });

0 个答案:

没有答案