如果 firestore 在 collection 中获取特定值,则用户信息不会显示在 recyclerview 中

information of the user doesn't show in recyclerview in getting a specific value in a collection if firestore

我正在开发一个项目,其中用户发送 his/her 订单,管理员将收到它以准备交付该订单。

问题

我在收到客户的上述订单时在管理员端获取数据时遇到问题

由于某些原因,RecyclerView 中只出现了订单的时间,其余的没有出现。

如果有效的话应该是这样的

我正确设置了模型和适配器,所以我认为问题出在 recyclerview 代码上,并且我在 LogCat

中没有收到任何错误
     userOrderAdminRec = findViewById(R.id.admin_order_rcv);
        userOrderAdminRec.setLayoutManager(new LinearLayoutManager(this,RecyclerView.VERTICAL,false));
        adminUserDetailModelList = new ArrayList<>();
        adminUserDetailAdapter = new AdminUserDetailAdapter(this,adminUserDetailModelList);
        userOrderAdminRec.setAdapter(adminUserDetailAdapter);

        firestore.collection("UserOrder")
                .get()
                .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()){
                            for (QueryDocumentSnapshot documentSnapshot : task.getResult()){

                                AdminUserDetailModel adminUserDetailModel = documentSnapshot.toObject(AdminUserDetailModel.class);
                                adminUserDetailModelList.add(adminUserDetailModel);
                                adminUserDetailAdapter.notifyDataSetChanged();

                            }
                        }
                        else {

                            Toast.makeText(AdminOrderActivity.this, "Error"+task.getException(), Toast.LENGTH_SHORT).show();
                        }
                    }
                });



    }
    private void orderList() {
      

        FirebaseFirestore db = FirebaseFirestore.getInstance();
        CollectionReference userCartOrder = db.collection("UserOrder").document().collection("CartID");
        CollectionReference userCartID = db.collection("ItemOrder");

        Query query = userCartID.whereEqualTo("CartID",userCartOrder);

        query.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
            @Override
            public void onComplete(@NonNull Task<QuerySnapshot> task) {
                if (task.isSuccessful()){
                    for (QueryDocumentSnapshot documentSnapshot: task.getResult()){
                        AdminUserDetailModel adminUserDetailModel = documentSnapshot.toObject(AdminUserDetailModel.class);
                        adminUserDetailModelList.add(adminUserDetailModel);
                    }
                    adminUserDetailAdapter.notifyDataSetChanged();
                }
                else {
                    Toast.makeText(AdminOrderActivity.this, "Query failed", Toast.LENGTH_SHORT).show();
                }
            }
        });

如果需要的话,这是我的 collection 在 firestore

AdminUserDetailModel

public class AdminUserDetailModel {

    String name;
    String address;
    String phoneNumber;
    String cartID;
    String totalPrice;
    String currentTime;
    String itemList;
    String productName;
    String productQuantity;

    public AdminUserDetailModel() {
    }

    public AdminUserDetailModel(String name,String productName,String productQuantity, String address, String phoneNumber, String cartID, String totalPrice, String currentTime, String itemList) {
        this.name = name;
        this.address = address;
        this.phoneNumber = phoneNumber;
        this.cartID = cartID;
        this.totalPrice = totalPrice;
        this.currentTime = currentTime;
        this.itemList = itemList;
        this.productName = productName;
        this.productQuantity = productQuantity;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getCartID() {
        return cartID;
    }

    public void setCartID(String cartID) {
        this.cartID = cartID;
    }

    public String getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(String totalPrice) {
        this.totalPrice = totalPrice;
    }

    public String getCurrentTime() {
        return currentTime;
    }

    public void setCurrentTime(String currentTime) {
        this.currentTime = currentTime;
    }

    public String getItemList() {
        return itemList;
    }

    public void setItemList(String itemList) {
        this.itemList = itemList;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public String getProductQuantity() {
        return productQuantity;
    }

    public void setProductQuantity(String productQuantity) {
        this.productQuantity = productQuantity;
    }
}

for some reason only the time of the order appeared in the RecyclerView and the rest doesn't appear.

这是预期的行为,因为 class 中与数据库中的字段匹配的唯一字段是 currentTime。 class 中的所有其他字段都以小写字母开头,而在您的数据库中以大写字母开头,因此出现了这种行为。在您的 class 中查看 address(小写字母 a),而在您的数据库中查看 Address(大写字母 A)? class 中的名称必须与数据库中的名称匹配。

要解决这个问题,您可以更改 class 中的名称以匹配数据库中的名称,反之亦然,或者您可以在 getter 前面使用注释,如下所示:

@PropertyName("Address")
public String getAddress() {
    return address;
}