0

I have created an "Order Placed" database and retrieved values in it from two model classes. I want to show the product details according to the order ids and the user details of the user to the admin in recycler view. Please help. Not able to retrieve this database in the recycler view. I am attaching the pic of my database. Please help. I am new in this.

EDIT: ADDING THE CODE. IT'S NOT RETRIEVING THE DATA.

Database image

List<product_details> list = new ArrayList<>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_admin_user_products_display);
    // Assign id to RecyclerView.
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView3);




    recyclerView.setHasFixedSize(true);
    FAuth = FirebaseAuth.getInstance();
    currentuser = FAuth.getCurrentUser().getUid();
    recyclerView.setLayoutManager(newLinearLayoutManager(AdminUserProductsDisplay.this));
    AData = FirebaseDatabase.getInstance().getReference("Orders Placed").child(currentuser);


    AData.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot postSnapshot : dataSnapshot.getChildren()) {
                


                            product_details imageUploadInfo = postSnapshot.getValue(product_details.class);
                            list.add(imageUploadInfo);

                        }
                        adapter = new com.example.ecom.AdminUserProductRecycler(getApplicationContext(), list);

                        recyclerView.setAdapter(adapter);
                    
        }
        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });

}

}

1 Answers1

0

First, you have to get the data from Firebase Database

 private DatabaseReference mDatabase;
 mDatabase = FirebaseDatabase.getInstance().getReference();

 mDatabase.child("Orders Placed").child(id).child(Order 
 ids).addListenerForSingleValueEvent(
                new ValueEventListener() {
                    @Override
                    public void onDataChange(DataSnapshot dataSnapshot) {


                        // HANDLE DATA and PASS TO ADAPTER ATTACHED TO RECYCLER VIEW
                      
                   
                    }

                    @Override
                    public void onCancelled(DatabaseError databaseError) {
                        Log.w(TAG, "getUser:onCancelled", databaseError.toException());
                        
                    }
                });

For Recycler view Implementation Follow this

Simple Android RecyclerView example

UPDATE

try creating and assigning the adapter right where you are setting the layout manager, then just call

adapter.notifyDataSetChanged(); 

inside the listener after adding data to list

Gouse Mohiddin
  • 420
  • 2
  • 7
  • Hey! thanks a lot for the response. i did the same thing still it is not retrieving the data. i am adding the code. Please suggest something. i m stuck on this for a week now. – Anisha Agarwal Jun 22 '20 at 08:34
  • i want to display both the orders of the user and the user details to the admin as stored in the database. i have attched the db image as well. – Anisha Agarwal Jun 22 '20 at 08:51