如何获取子项的值的推送ID(" topic_name")。getValue()=" algebre" ? FirebaseDatabase结构:
我已经尝试过push()。getKey();但它给我带来了另一把钥匙。
答案 0 :(得分:1)
试试这个:
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
Query query = reference.child(TOP_NODE_NAME).orderByChild("topic_name").equalTo("algebre");
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot child : dataSnapshot.getChildren()) {
String key = child.getKey();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
现在key
拥有topic_name=algebra
答案 1 :(得分:-1)
尝试这个来获取ID ..
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
reference.push().getKey();
并在子节点内搜索,然后进行如下查询..
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
Query query = reference.child("topic_name").equalTo("algebre").orderByKey();
query.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.exists()) {
for (DataSnapshot issue : dataSnapshot.getChildren()) {
Log.d("Value::", issue.getValue(Child.class).key); // field name you need to print.
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});