在Firebase数据库中的数据混乱。

huangapple go评论88阅读模式
英文:

mixed up data in firebase database data

问题

以下是您提供的代码的翻译:

我是firebase和Android编程的新手。在我的应用程序中,我只是保存了fullName、password、phoneNumber、Email、gender和确认密码。所有这些字段都存储在数据库中,但它们混在一起了。

用户
+23407066082195
电子邮件:'0000'

fullName:'+23407066082195'

性别:'男'

密码:'k..gmail.com'

电话号码:'Tim...'

重新输入的密码:'0000'

这是我的第一个活动的代码:

btnSignUp = findViewById(R.id.btnSignUp);
btnSignUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!validateEdtName() | !validateEdtEmail() | !validatePhoneNumber() | !validateEdtPassword() | !validateEdtRePassword() | !validateGender()) {
return;
}
progressBar.setVisibility(View.VISIBLE);
selectedGender = findViewById(gender.getCheckedRadioButtonId());
String gender = selectedGender.getText().toString();

    String myName = fullName.getEditableText().toString().trim();
    String myEmail = email.getEditableText().toString().trim();
    String myPassword = password.getEditableText().toString().trim();
    String myRetypedPassword = retypedPassword.getEditableText().toString().trim();

    String getUserEnteredPhoneNumber = phoneNumber.getEditableText().toString().trim();
    String phoneNo = "+" + countryCodePicker.getFullNumber() + getUserEnteredPhoneNumber;

    Intent intent = new Intent(SignUp.this, VerifyOTP.class);

    intent.putExtra("PhoneNumber", phoneNo);
    //intent.putExtra("fullName", fullName);
    intent.putExtra("myName", myName);
    intent.putExtra("myEmail", myEmail);
    intent.putExtra("myPassword", myPassword);
    intent.putExtra("myRetypedPassword", myRetypedPassword);
    intent.putExtra("gender", gender);

    startActivity(intent);
}

});

对于下一个活动:创建了一个用于保存字符串的类,名为UserHelperClass

FirebaseDatabase rootNode = FirebaseDatabase.getInstance();
DatabaseReference reference = rootNode.getReference("Users");

UserHelperClass addNewUser = new UserHelperClass(fullName,phoneNo,password,email,retypedPassword,gender);
reference.child(phoneNo).setValue(addNewUser);

任何建议都将有所帮助。

英文:

I am new to firebase and Android programming in general. In my app I'm simply saving fullName, password, phoneNumber, Email, gender and a confirmed password. All these fields get stored in the database but their mixed up

Users
+23407066082195
email: '0000'

fullName: '+23407066082195'

gender: 'male'

password: 'k..gmail.com'

phoneNo: 'Tim...'

retypedPassword: '0000'

this is my code : for the first activity

 btnSignUp = findViewById(R.id.btnSignUp);
 btnSignUp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (!validateEdtName() | !validateEdtEmail() | !validatePhoneNumber() | !validateEdtPassword() | !validateEdtRePassword() | !validateGender()) {
                return;
            }
            progressBar.setVisibility(View.VISIBLE);
            selectedGender = findViewById(gender.getCheckedRadioButtonId());
            String gender = selectedGender.getText().toString();

            String myName = fullName.getEditableText().toString().trim();
            String myEmail = email.getEditableText().toString().trim();
            String myPassword = password.getEditableText().toString().trim();
            String myRetypedPassword = retypedPassword.getEditableText().toString().trim();

            String getUserEnteredPhoneNumber = phoneNumber.getEditableText().toString().trim();
            String phoneNo = "+" + countryCodePicker.getFullNumber() + getUserEnteredPhoneNumber;

            Intent intent = new Intent(SignUp.this, VerifyOTP.class);

            intent.putExtra("PhoneNumber", phoneNo);
            //intent.putExtra("fullName", fullName);
            intent.putExtra("myName", myName);
            intent.putExtra("myEmail", myEmail);
            intent.putExtra("myPassword", myPassword);
            intent.putExtra("myRetypedPassword", myRetypedPassword);
            intent.putExtra("gender", gender);

            startActivity(intent);

for the next activity: created a class to hold the strings which is the UserHelperClass

FirebaseDatabase rootNode = FirebaseDatabase.getInstance();
DatabaseReference reference = rootNode.getReference("Users");

UserHelperClass addNewUser = new UserHelperClass(fullName,phoneNo,password,email,retypedPassword,gender);
reference.child(phoneNo).setValue(addNewUser);

any suggestions will be helpful.

答案1

得分: 0

我分析了你的代码。要么你没有正确初始化你的EditText(也许它们的ID不正确),要么你没有正确实现UserHelperClass的构造函数。检查它们两个,你可能会找到bug。

P.S. 我鼓励你查看Parcelable文档。它是用于通过意图分享对象的。

英文:

I analyzed your code. Either you haven't correctly initialized your EditTexts (maybe their ids aren't correct) or you haven't correctly implemented the constructor of UserHelperClass. Check both of them, you will probably see the bug.

P.S. I would encourage you to check Parcelable documentation. It is for sharing objects via intents.

huangapple
  • 本文由 发表于 2020年8月11日 06:24:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/63348825.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定