gpt4 book ai didi

java - 获取节点的父节点(Firebase)

转载 作者:行者123 更新时间:2023-12-05 00:20:23 24 4
gpt4 key购买 nike

我是 android 应用程序的初学者,谁能帮助我并告诉我如何检索当前用户 ID 的生成的 id 值节点?请在我的代码下面找到。谢谢

enter image description here

FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
FirebaseDatabase mDatabase = FirebaseDatabase.getInstance();
DatabaseReference mDb = mDatabase.getReference();
FirebaseUser user = firebaseAuth.getCurrentUser();
final String userKey = user.getUid();

mDb.child("students").child(currentuser).getRef().addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String reference = dataSnapshot.getRef().toString();
String userID = dataSnapshot.child("level").getValue(String.class);
textViewStudentName.setText(reference);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});

最佳答案

试试下面得到level :

DatabaseReference fireReference = FirebaseDatabase.getInstance().getReference("students");

fireReference.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

for(DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
if(childSnapshot.hasChild(userKey)) {

String userID = childSnapshot.child(userKey).child("level").getValue(String.class);

break;
}
}
}

@Override
public void onCancelled(@NonNull DatabaseError databaseError) {

}
});

关于java - 获取节点的父节点(Firebase),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59810190/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com