简体   繁体   English

我如何获取具有相同String key android firebase的所有项目

[英]How do I get all the items which have same String key android firebase

I want to get all the items which have same league id 我想获得所有具有相同联赛ID的物品

I want to get all the items which have same league id within the teams node and in that node I have push key and then an object, with Firebase query , If any one knows about it please help. 我想获取所有在team节点中具有相同联赛ID的物品,并且在该节点中我有一个按键,然后有一个对象,使用Firebase查询,如果有人知道它,请帮助。 Link to Image -> https://i.stack.imgur.com/XzJo2.jpg 链接到图像-> https://i.stack.imgur.com/XzJo2.jpg
and result is > System.out: LOG DataSnapshot { key = teams, value = null } 结果为> System.out:LOG DataSnapshot {键=组,值= null}

val query = databaseRef.child("teams").orderByChild("leagueId").equalTo("LS9t7MgdIuHrDP0vEME")
            query.addListenerForSingleValueEvent(object : ValueEventListener {
                override fun onDataChange(dataSnapshot: DataSnapshot) {
                    println("LOG $dataSnapshot")

                }

                override fun onCancelled(databaseError: DatabaseError) {

                }
            })

To get all the items within the teams node that correspond to a specific id, please use the following lines of code: 要获取teams节点中与特定ID对应的所有项目,请使用以下代码行:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
Query query = rootRef.child("teams").orderByChild("leagueId").equalsTo(desiredId);
ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            String team = ds.child("team").getValue(String.class);
            Log.d(TAG, team);
        }
    }

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

In which the desiredId should hold a value as -LS9t ... vEME . 其中desiredId的值应为-LS9t ... vEME The output in your logcat will be, the name of all teams that have the id equal to -LS9t ... vEME . 您的logcat中的输出将是ID等于-LS9t ... vEME的所有团队的名称。

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

相关问题 Android通过键(日期)订购Firebase项目 - Android order Firebase items by key which is a date Android Array 列表过滤器和分组具有相同键值的项目 - Android Array list filter and group items which have the same key value Android Firebase - 如何将 DatabaseReference 设置为为所有用户生成的推送密钥? - Android Firebase - How do I set DatabaseReference to a generated push key for all users? 如何在 firebase 数据库中获取特定键并比较它们是否相同? - How do I get a specific key in the firebase databse and compare them if they are the same? android所有BottomNavigationView项目具有相同的颜色 - android all BottomNavigationView items have same color Android Firebase:如何简单地获取某个键下的所有值? - Android Firebase: How to simply get all the values under a certain key? 如何在Android的Firebase数据库中获取具有选定值的节点的密钥UID? - How do i get the key UID of a node with a selected value in firebase database in android? 如何获得由 Firebase 实时数据库为 Android 分配的随机密钥? - How do I get a random key assigned by Firebase Realtime Database for Android? 我如何在 firebase 数据库中使用相同的键来总结值 - How do i sum up values with the same key in firebase database 如何在Java / Android中按降序获取Firebase项目 - How can I get firebase items in descending order in Java / Android
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM