1

My RecyclerView is empty, should be filled with uploaded pictures from database. I followed instructions from simplifiedcoding, not sure what's wrong.

//recyclerview object
private RecyclerView recyclerView;

//adapter object
private RecyclerView.Adapter adapter;

//database reference
private DatabaseReference mDatabase;

//progress dialog
private ProgressDialog progressDialog;

//list to hold all the uploaded images
private List<Upload> uploads;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_show_images);



    //adding adapter to recyclerview


    progressDialog = new ProgressDialog(this);

    uploads = new ArrayList<>();

    //displaying progress dialog while fetching images
    progressDialog.setMessage("Please wait...");
    progressDialog.show();
    mDatabase = FirebaseDatabase.getInstance().getReference(Constants.DATABASE_PATH_UPLOADS);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));



    //adding an event listener to fetch values
    mDatabase.addValueEventListener(new ValueEventListener() {


        @Override
        public void onDataChange(DataSnapshot snapshot) {
            //dismissing the progress dialog
            progressDialog.dismiss();

            //iterating through all the values in database
            for (DataSnapshot postSnapshot : snapshot.getChildren()) {
                Upload upload = postSnapshot.getValue(Upload.class);
                uploads.add(upload);
            }
            //creating adapter
            recyclerView.setAdapter(adapter);
            recyclerView.setHasFixedSize(true);


        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            progressDialog.dismiss();
        }
    });

}
}
AL.
  • 36,815
  • 10
  • 142
  • 281

0 Answers0