Reputation: 89
I have Done this:
adapter.getRef(currentPosition).addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
adapterKey = dataSnapshot.getChildren().toString();
Log.i("adapterKey",adapterKey);
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
I want to retrieve the Id's generated by firebase
in order to access the inner data to EndUsers
node. How can I do that?
Upvotes: 0
Views: 1754
Reputation: 3
DatabaseReference mDatabaseReference; //you must initialize it
mDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
Log.i(TAG, "the key is : " + child.getKey());
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Upvotes: 1
Reputation: 1221
Try like this
for(DataSnapshot snapshot:dataSnapshot.getChildren()){
//snapshot.getKey()
//snapshot.getValue()
}
Upvotes: 2