Reputation: 45
I would like to get all objects in my firebaseRecyclerAdapter as List.
Here is what I try ;
Query query = FirebaseDatabase.getInstance()
.getReference()
.child("ABC").orderByChild("abc");
FirebaseRecyclerOptions<myObject> options =
new FirebaseRecyclerOptions.Builder<myObject>()
.setQuery(query, myObject.class)
.build();
adapterL = new myAdapter(options, MyActivity.this);
ObservableSnapshotArray<myObject> mSnapshots=adapterL.getSnapshots();
if(mSnapshots.size()!=0) {
...
}
But always I am getting mSnapshots size 0. I thought, probably the firebase adapter not loaded yet, but I dont know.
So question; after query to firebase, how can I get the object list in firebase adapter ? Thank you for suggestions.
Upvotes: 1
Views: 513
Reputation: 4007
You'll want to use this:
snapshots.addChangeEventListener(object : ChangeEventListener {
override fun onChildChanged(
type: ChangeEventType,
snapshot: DocumentSnapshot,
newIndex: Int,
oldIndex: Int
) {
// An individual item has been changed
}
override fun onDataChanged() {
// A full update has been received and processed.
// Here's where you would use `snapshots` and process stuff
}
override fun onError(e: FirebaseFirestoreException) {}
})
Upvotes: 1