本文介绍了适用于Android的Firebase,如何循环播放子节点(对于每个子节点= x do y)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的测试结果:
System.out.println (都是EmailString);
我发现列出对象的唯一方法是使用firebaseAdapter,还有另一种方法吗?
解决方案
最简单的方法是使用ValueEventListener。
FirebaseDatabase.getInstance()。getReference()。child(users)
.addListenerForSingleValueEvent(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot) dataSnapshot){
for(DataSnapshot snapshot:dataSnapshot.getChildren()){
User user = snapshot.getValue(User.class);
System.out.println(user.email);
}
}
@Override
public void onCancelled(DatabaseError databaseError){
}
});
This is what my test looks like:
I won't use the fields above, it's just a dummy. But I would like to go through all the children on "users" and for each email return a:
System.out.println(emailString);
The only way I found of listing an object is using firebaseAdapter, is there another way of doing it?
解决方案
The easiest way is with a ValueEventListener.
FirebaseDatabase.getInstance().getReference().child("users")
.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
User user = snapshot.getValue(User.class);
System.out.println(user.email);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
这篇关于适用于Android的Firebase,如何循环播放子节点(对于每个子节点= x do y)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!