我做了这个:
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) {
}
});
我想检索由firebase
生成的ID,以便访问EndUsers
节点的内部数据。我怎么能这样做?
答案 0 :(得分:1)
试试这个
for(DataSnapshot snapshot:dataSnapshot.getChildren()){
//snapshot.getKey()
//snapshot.getValue()
}
答案 1 :(得分:1)
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) {
}
});