英文:
How can I get the correct DatabaseReference
问题
USER PROFILE
private void showUserProfile(FirebaseUser firebaseUser) {
String userID = firebaseUser.getUid();
DatabaseReference referenceProfile = FirebaseDatabase.getInstance().getReference("Users");
referenceProfile.child(userID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
ReadWriteUserDetails readUserDetail = snapshot.getValue(ReadWriteUserDetails.class);
if (readUserDetail != null) {
fullname = firebaseUser.getDisplayName();
email = firebaseUser.getEmail();
doB = readUserDetail.birthday;
discount = readUserDetail.discount;
textViewFullName.setText(fullname);
textViewEmail.setText(email);
textViewDoB.setText(doB);
textViewDiscount.setText(discount);
}
}
Firebase
ReadWriteUserDetail class
public class ReadWriteUserDetails {
public String birthday, discount;
public ReadWriteUserDetails() {
}
public ReadWriteUserDetails(String textBirthday, String textDiscount) {
this.birthday = textBirthday;
this.discount = textDiscount;
}
}
英文:
I am creating a user profile but I do not know how can I get the child node and display it in the user profile, How can I reference this correctly? I would greatly appreciate any comments or suggestion, thank you in advance!!
USER PROFILE
private void showUserProfile( FirebaseUser firebaseUser) {
String userID = firebaseUser.getUid();
DatabaseReference referenceProfile = FirebaseDatabase.getInstance().getReference("Users");
// 👆
referenceProfile.child(userID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
ReadWriteUserDetails readUserDetail = snapshot.getValue(ReadWriteUserDetails.class);
if(readUserDetail != null){
fullname = firebaseUser.getDisplayName();
email = firebaseUser.getEmail();
doB = readUserDetail.birthday;
discount = readUserDetail.discount;
textViewFullName.setText(fullname);
textViewEmail.setText(email);
textViewDoB.setText(doB);
textViewDiscount.setText(discount);
}
}
Firebase
ReadWriteUserDetail class
public class ReadWriteUserDetails {
public String birthday, discount;
public ReadWriteUserDetails(){};
public ReadWriteUserDetails(String textBirthday, String textDiscount){
this.birthday = textBirthday;
this.discount = textDiscount;
}
}
答案1
得分: 0
你将用户配置文件存储在数据库的路径/Users/Customers
下,因此可以设置对该父节点的引用如下:
DatabaseReference referenceProfile =
FirebaseDatabase.getInstance().getReference("Users/Customers");
英文:
You're storing your user profiles under path /Users/Customers
in your database, so you can set up a reference to that parent node as:
DatabaseReference referenceProfile =
FirebaseDatabase.getInstance().getReference("Users/Customers");
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论