//这是我尝试检索数据的方法
@Override
protected void onStart() {
super.onStart();
String uid = (String) firebaseAuth.getCurrentUser().getUid();`//setting auth uid to uid variable`
databaseReference = FirebaseDatabase.getInstance().getReference().child("users").child("profiles").child(uid);
//使用addValue事件列表器
databaseReference.child("users").child("profiles").child(uid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String name = (String)dataSnapshot.child("name").getValue();
text.setText(name);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
//这是我的数据库
用户
profiles
GUiQKxqij3bv4wRCaBcMuN6UNlD3
address:"Mount Lavinia"
name:"Hemal Herath"
tel:"0702221617"
url:"https://firebasestorage.googleapis.com/v0/b/csa..."
答案 0 :(得分:0)
databaseReference.child("users").child("profiles").child(uid).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot singleSnapShot: dataSnapshot.getChildren()) {
switch(singleSnapShot.getKey())
{
case "address":
addressText.setText(singleSnapShot.getValue());
break;
case "name":
nameText.setText(singleSnapShot.getvalue());
break;
case "tel":
telText.setText(singleSnapShot.getvalue());
break;
case "url":
urlText.setText(singleSnapShot.getvalue());
break;
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}