首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在单独的变量中检索Firebase数据库Android的子节点?

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

Stack Overflow用户
提问于 2019-05-06 19:27:46
回答 1查看 28关注 0票数 1

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

我的数据库屏幕截图

代码语言:javascript
复制
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);
              }
          }
});

但不知何故,我无法检索和存储值。需要帮助吗?

EN

回答 1

Stack Overflow用户

发布于 2020-05-16 17:06:00

尝试使用getKey()而不是child()。

代码语言:javascript
复制
          if(dataSnapshot.getKey().equals("Continental")){
             Continental = dataSnapshot.getValue(String.class);
             cityTextOne.setText(Continental);
          }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56004301

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档