[英]Retrieve child nodes Firebase Database Android into separate variables?
Retrieve child nodes into separate variables from Firebase Database Android.从 Firebase 数据库 Android 中将子节点检索到单独的变量中。
Screenshot of my database我的数据库截图
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myNewRef = database.getReference("F-5/Islamabad Marriott Hotel");
myNewRef.addChildEventListener(new ChildEventListener() {
public String FastFood;
public String Desi;
public String Continental;
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
if(dataSnapshot.child("Continental")!= null){
Continental = dataSnapshot.getValue(String.class);
cityTextOne.setText(Continental);
}
if(dataSnapshot.child("Desi")!= null){
Desi = dataSnapshot.getValue(String.class);
cityTextTwo.setText(Desi);
}
if(dataSnapshot.child("Fast-Food")!= null){
FastFood = dataSnapshot.getValue(String.class);
cityTextThree.setText(FastFood);
}
}
});
But somehow I cannot retrieve and store the values.但不知何故,我无法检索和存储这些值。 Need Help?
需要帮忙?
Try getKey() instead of child().尝试 getKey() 而不是 child()。
if(dataSnapshot.getKey().equals("Continental")){
Continental = dataSnapshot.getValue(String.class);
cityTextOne.setText(Continental);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.