I have some data under same reference in the database and I'm trying to store it in a ArrayList<String>
.
Here's how:
mDatabase.child("child").child(uid).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if (dataSnapshot.getValue() != null){
ids.add(dataSnapshot.getValue().toString());
Log.d("ids", ids.toString());
} else {
Toast.makeText(getBaseContext(), "No data!", Toast.LENGTH_SHORT).show();
}
}
...
...
});
The reference mDatabase.child("child").child(uid)...
has 2 keys stored in it and they are getting stored in ids
one-by-one like this:
D/ids: [-Kayr_ENTy4QZQKn3Bgx]
D/ids: [-Kayr_ENTy4QZQKn3Bgx, -KaywN_5pTOrB0ooBIC3]
What I want to know is how to make them get added at once in ids
and not one-by-one?
UPDATE 1:-
the data structure is kind of like this:
-app
-child
-uid
-1484967071: -Kayr_ENTy4QZQKn3Bgx
-1484967222: -KaywN_5pTOrB0ooBIC3
and using valueEventListener()
, as suggested by cartant, is resulting in this getting retrieved:
D/ids: [{1484967222=-KaywN_5pTOrB0ooBIC3, 1484967071=-Kayr_ENTy4QZQKn3Bgx}]
though I only want the keys, which are -KaywN_5pTOrB0ooBIC3
and -Kayr_ENTy4QZQKn3Bgx
.