简体   繁体   English

将子节点 Firebase 数据库 Android 检索到单独的变量中?

[英]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.

相关问题 Android,Firebase-尝试检索多个子节点时,数据库仅将单个子节点作为字符串返回 - Android, Firebase - database only returns single child node as string when trying to retrieve multiple child nodes Firebase数据库从子android访问节点 - Firebase Database accessing nodes from child android 如何在 android 工作室中从 firebase 检索多个子节点 - How to retrieve mulitple child nodes from firebase in android studio Android Firebase数据库如何从子节点检索所有数据 - android firebase database how to retrieve all data from child node 如何在firebase数据库中检索特定孩子的数据 - android studio/java? - How to retrieve data for a specific child in firebase database - android studio/ java? Android Studio Firebase数据库检索多个子项的子项值 - Android studio firebase database retrieve child value for multiple childs 如何从多层多个子节点内的 Firebase 数据库中检索数据? - How to retrieve the data from Firebase Database inside muti-layer multiple child nodes? 如何在Firebase数据库Android上获取具有相似子节点的所有父节点? - How to fetch all parent nodes with similar child nodes on Firebase database Android? 通过firebase android开发中的循环从子节点检索特定数据 - Retrieve specific data from child nodes through loop in firebase android development 访问 Android 的 Firebase 中的父节点和子节点 - Accessing parent and child nodes in Firebase for Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM