Reputation: 1
I am using Firebase realtime database in my app. I have listView and adapter that each view of the adapter load one item from the Firebase database. But it takes few seconds to load all of the data (each item has image and name). So I want to show progress bar or something to show to the user, but I don't know where to put it.
I thought about using asynctask or something, but the problem is that I don't really know where the data are loaded. I am attaching child event listener to Firebase database reference object, so any time a new child is added, the adapter will be updated, but I don't know how to know that all of the children had finished to load.
Hope you understand me and help me.
Upvotes: 0
Views: 3293
Reputation: 358
see this is a function to set some data:--
private void addUserChangeListener() {
*** you can initialize your progress dialog here
// User data change listener
mFirebaseDatabase.child(userId).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
// Check for null
if (user == null) {
Log.e(TAG, "User data is null!");
return;
}
Log.e(TAG, "User data is changed!" + user.name + ", " + user.email);
*** here you can check if the progress dialog is not null then close your progress dialog here
// Display newly updated name and email
txtDetails.setText(user.name + ", " + user.email);
// clear edit text
inputEmail.setText("");
inputName.setText("");
toggleButton();
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
***also close your progress dialog here
Log.e(TAG, "Failed to read user", error.toException());
}
});
}
Upvotes: 1