简体   繁体   English

如何在Firebase实时数据库中获取子名称

[英]How to fetch child names in Firebase realtime database

This is my Firebase database. 这是我的Firebase数据库。 I want to fetch only the child names of Intake-Sec like CSE, EEE . 我只想获取Intake-Sec的子名称,例如CSE, EEE Not the children of CSE or EEE . 不是CSEEEE的子代。 How can I do this? 我怎样才能做到这一点?

在此处输入图片说明

Thanks in advance! 提前致谢!

To get only the CSE and EEE , please use the following lines of code: 要仅获取CSEEEE ,请使用以下代码行:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        List<String> list = new ArrayList<>();
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            String key = ds.getKey();
            list.add(key);
            Log.d(TAG, key);
        }

        //Do what you need to do with your list
    }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {
        Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
    }
};
rootRef.addListenerForSingleValueEvent(valueEventListener);

The list will contains only two elements as it will also be printed in the logcat: 该列表将仅包含两个元素,因为它还将被打印在logcat中:

CSE
EEE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从firebase实时数据库中获取数据 - how to fetch data from firebase realtime database 如何从 Firebase 实时数据库中获取不同节点的数据? - How to fetch the data from different node from Firebase realtime database? 如何从 firebase 实时数据库中获取数据并在微调器上显示 - How to fetch data from firebase realtime database and display it on spinner 如何从 firebase 实时数据库子访问数据? - How to access data from firebase Realtime database child? 如何在RecyclerView中访问许多嵌套子Firebase Realtime数据库? - How to Access Many Nested Child Firebase Realtime database into RecyclerView? 如何检查 Firebase 实时数据库中是否存在子子项? - How to check if sub child exists in Firebase Realtime Database? 如何在 Firebase 实时数据库中的特定子树中推送值 - How to push value in specific child tree in Firebase Realtime Database Firebase 不在实时数据库中创建任何子节点 - Firebase not creating any child in Realtime database Firebase Realtime Database随机选择子节点后如何获取子节点的key - How to get the key of a child node in Firebase Realtime Database after choosing a child randomly 如何使用 Firebase 实时数据库中的关联节点名称列表填充“微调器”? - How can I populate the 'Spinner' with a list of associated node names from the Firebase Realtime Database?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM