答案 0 :(得分:1)
试试这个:
DatabaseReference ref=FirebaseDatabase.getInstance().getReference().child("masterSheet");
ref.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot){
for(DataSnapshot data: dataSnapshot.getChildren()){
String email=data.child("3").getValue().toString();
DatabaseReference refs=FirebaseDatabase.getInstance().getReference().child("EmailList").push();
refs.child("email").setValue(email);
}
}
@Override
public void onCancelled(FirebaseError firebaseError) {
}
});
在这里你有masterSheet
的快照然后你在masterSheet
的孩子里面迭代并获得孩子的价值(" 3")这是电子邮件然后你使用父节点onDatachange
EmailList
内创建一个新引用(因为它是异步的)
答案 1 :(得分:0)
final ArrayList<String> emails = new ArrayList<>();
DatabaseReference masterSheetReferebce =FirebaseDatabase.getInstance().getReference().child("masterSheet");
masterSheetReferebce.addListenerForSingleValueEvent(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot dataSnapshot){
//Get All the emails
for(DataSnapshot data: dataSnapshot.getChildren()){
String email=data.child("3").getValue().toString();
emails.add(email);
}
//Instead of posting everytime just post it once
//adding email list to child EmailList
DatabaseReference emailListReference=FirebaseDatabase.getInstance().getReference().child("EmailList");
emailListReference.setValue(emails);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});