0

I have a retrieve function which gets the data from the firebase database and the code as following:

FirebaseFirestore.getInstance().collection("products")
            .get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()){
                        for (int i=0; i<task.getResult().size(); i++){
                            Products p = new Products();
                            String Userid = task.getResult().getDocuments().get(i).getData().get("UserID").toString();
                            Log.d(TAG, "onComplete: "+Userid);

                            if (Userid.equals(FirebaseAuth.getInstance().getCurrentUser().getUid())){
                                String price = task.getResult().getDocuments().get(i).getData().get("productPrice").toString();
                                String Image = task.getResult().getDocuments().get(i).getData().get("UrlImage0").toString();
                                String title = task.getResult().getDocuments().get(i).getData().get("productName").toString();
                                // add all these data to the product  class
                                Log.d(TAG, "onComplete: "+price+ title+Image);
                                p.setTitle(title);
                                p.setPrice(price);
                                p.setProductImage(Image);
                                viewProduct.onSuccess(p);
                            }



                            viewProduct.onSuccess(p);
                        }

                    }else {
                        viewProduct.onError("Something went wrong");
                    }
                }
            });

and my loading the data into recyclerview with gridview and the code as following:

ListDataView.setLayoutManager(new GridLayoutManager(this, 2));
    ListDataView.setHasFixedSize(true);
    ListOutDateAdapter = new productAdapter(this, OutDateTrip);
    ListDataView.setAdapter(ListOutDateAdapter);
  //  ListDataView.invalidate();
    ListDataView.setHasFixedSize(true);
    ListDataView.addItemDecoration(new DividerItemDecoration(ListDataView.getContext(), DividerItemDecoration.VERTICAL));

The issue *It keeps loading the data as showing on the image * enter image description here

I already check the following post but It did not address up my issue enter link description here

Abdulmalek
  • 105
  • 1
  • 10

1 Answers1

0

I have reviewed a code, again and again, the issue I have to add the items twice to the product's list so I have removed one and everything is fine;

Abdulmalek
  • 105
  • 1
  • 10