Reputation: 107
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
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
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