Home > OS >  information of the user doesn't show in recyclerview in getting a specific value in a collectio
information of the user doesn't show in recyclerview in getting a specific value in a collectio

Time:02-25

I'm working on a project where a user sends his/her order and the admin will receive it in order to prepare the said order to deliver it.

Problem

I'm having trouble fetching the data on the admin side when receiving the said order from the customer

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

enter image description here

This is how it should appear if it works

enter image description here

I did the model and adapter right so I assume that the problem came to the recyclerview codes and I receive no error in the 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();
                }
            }
        });

this is my collection in the firestore if it's needed

enter image description here

enter image description here

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;
    }
}

CodePudding user response:

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

That's the expected behavior since the only field in your class that matches the one in the database is the currentTime. All the other fields in your class start with a lowercase letter, while in your database start with a capital letter, hence that behavior. See address (lowercase letter a) in your class, vs. Address (the capital letter A) in your database? The name in your class must match the one in the database.

To solve this, you either change the names in your class to match the one in the database, or vice versa, or you can use an annotation in front of the getters like this:

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