Too Low
Too Low

Reputation: 107

How to use progress bar while loading documents from firestore

I am trying to retrive document from firestore. How do I add a progress bar while the document is loading? here's my code:

documentreference.addSnapshotListener(new EventListener<DocumentSnapshot>() {
                        @Override
                        public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
                            String UserId=documentSnapshot.getId();

                            ProductModel productModel1 = documentSnapshot.toObject(ProductModel.class).withId(UserId);
                            productModels.add(productModel1);
                            chatListAdapter.notifyDataSetChanged();




                        }
                    });

Upvotes: 1

Views: 1582

Answers (2)

jp santos
jp santos

Reputation: 1

documentreference.addSnapshotListener(new EventListener < DocumentSnapshot > () {
  @Override
  public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
    String UserId = documentSnapshot.getId();

    ProductModel productModel1 = documentSnapshot.toObject(ProductModel.class).withId(UserId);
    productModels.add(productModel1);
    chatListAdapter.notifyDataSetChanged();
    progressBar.setVisibilty(View.GONE);
  }
});

Upvotes: 0

Sagar Balyan
Sagar Balyan

Reputation: 658

Show the ProgressBar at the start of the activity i.e. just define a ProgressBar in xml and make sure its visible in the start.

Now, when all your data is loaded, just make it gone.

documentreference.addSnapshotListener(new EventListener < DocumentSnapshot > () {
  @Override
  public void onEvent(@Nullable DocumentSnapshot documentSnapshot, @Nullable FirebaseFirestoreException e) {
    String UserId = documentSnapshot.getId();

    ProductModel productModel1 = documentSnapshot.toObject(ProductModel.class).withId(UserId);
    productModels.add(productModel1);
    chatListAdapter.notifyDataSetChanged();
    progressBar.setVisibilty(View.GONE);
  }
});

Upvotes: 1

Related Questions