从Firebase数据库Android中将子节点检索到单独的变量中。
我的数据库屏幕截图

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);
}
}
});但不知何故,我无法检索和存储值。需要帮助吗?
发布于 2020-05-16 17:06:00
尝试使用getKey()而不是child()。
if(dataSnapshot.getKey().equals("Continental")){
Continental = dataSnapshot.getValue(String.class);
cityTextOne.setText(Continental);
}https://stackoverflow.com/questions/56004301
复制相似问题