从firebase android检索用户信息时遇到问题

时间:2017-12-29 21:48:10

标签: android database firebase firebase-realtime-database information-retrieval

个人资料片段代码

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_profile, container, false);


    Name = (EditText) rootView.findViewById(R.id.Name);
    Email = (EditText) rootView.findViewById(R.id.Email);
    Status = (EditText) rootView.findViewById(R.id.Status);
    Quote = (EditText) rootView.findViewById(R.id.Quote);

    mAuth = FirebaseAuth.getInstance();
    loadUserInformation();
    return rootView;
}

public void loadUserInformation() {

    FirebaseUser user = mAuth.getCurrentUser();

    if (user != null) {
        if (user.getName() != null) {
            Name.setText(user.getName());
        }
        if (user.getEmail() != null) {
            Email.setText(user.getEmail());
        }
        if (user.getStatus() != null) {
            Status.setText(user.getStatus());
        }
        if (user.getQuote() != null) {
            Quote.setText(user.getSQuote());
        }


    }
}

助手类

public class SetUpProfileHelper1 {

public String name;
public String email;
public String status;
public String quote;

public SetUpProfileHelper1(String name, String email, String status, String quote) {
    this.email = email;
    this.name = name;
    this.status = status;
    this.quote = quote;
}

public String getName() {
    return name;
}
public String getEmail() {
    return email;
}
public String getStatus() {
    return status;
}
public String getQuote() {
    return quote;
}

}

首先,用户注册。然后被带到setupprofile活动,他填写他的详细信息,如姓名,电子邮件等。我在Firebase中保存这些数据没有问题。有一个个人资料活动,用户应该可以在注册后查看他提供的姓名,电子邮件等详细信息。如何从Firebase检索数据并在EditText中显示它。请帮忙

1 个答案:

答案 0 :(得分:0)

假设您的数据库看起来像这样:

newRobot

请使用以下代码获取所需数据:

Firebase-root
    |
    --- users
          |
          --- uid1
          |     |
          |     --- //details
          |
          --- uid2
                |
                --- //details

输出将是您用户的所有名称。