本文介绍了在android firebase中获取父节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我当前的代码.如何获得名字的父节点
This is my current code. How can I get the parent node of the first name
final Query userQuery = mRef.orderByChild("First Name");
userQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
map.clear();
for (DataSnapshot child: dataSnapshot.getChildren())
{
String key = child.getKey().toString();
String value = child.getValue().toString();
map.put(key,value);
}
推荐答案
您应该在检索到的dataSnapshot
中调用getKey()
方法:
You should call the getKey()
method in your retrieved dataSnapshot
:
final Query userQuery = mRef.orderByChild("First Name");
userQuery.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
map.clear();
//Get the node from the datasnapshot
String myParentNode = dataSnapshot.getKey();
for (DataSnapshot child: dataSnapshot.getChildren())
{
String key = child.getKey().toString();
String value = child.getValue().toString();
map.put(key,value);
}
这篇关于在android firebase中获取父节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!