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