错误:
android.support.v7.widget.AppCompatEditText {8701551bVFED..CL。
....... 484,0-747,118#7f0b006c app:id / name_text
我正在尝试在注册过程中将用户的名称信息设置为FirebaseUser“ DisplayName”。我是android,java和firebase的新手。但是,尽管我进行了所有研究,但找不到任何解决方案。 id / name_text是从注册用户那里获取名称的编辑文本。我认为这是一个字符串问题,但无法解决。
救命。谢谢。
这是代码。
public class RegisterActivity extends AppCompatActivity {
@BindView(R.id.register_button) Button mRegisterButton;
@BindView(R.id.surname_edittext) EditText mSurnameEditText;
@BindView(R.id.name_text) EditText mNameEditText;
@BindView(R.id.password_edittext) EditText mPasswordEditText;
@BindView(R.id.mail_edittext) EditText mMailEditText;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
ButterKnife.bind(this);
mAuth = FirebaseAuth.getInstance();
}
@OnClick(R.id.register_button)
public void register_button(View view){
RegisterUser();
}
private void RegisterUser() {
String surname = mSurnameEditText.getText().toString().trim();
String name = mNameEditText.getText().toString().trim();
String password = mPasswordEditText.getText().toString().trim();
String mail = mMailEditText.getText().toString().trim();
if (TextUtils.isEmpty(name)) {
Toast.makeText(this, "enter the name", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(surname)) {
Toast.makeText(this, "enter the surname", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(password)) {
Toast.makeText(this, "enter the password", Toast.LENGTH_SHORT).show();
return;
}
if (TextUtils.isEmpty(mail)) {
Toast.makeText(this, "enter the mail", Toast.LENGTH_SHORT).show();
return;
}
mAuth.createUserWithEmailAndPassword(mail,password)
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
@Override
public void onComplete(@NonNull Task<AuthResult> task) {
if(task.isSuccessful()){
Toast.makeText(RegisterActivity.this,"Successfully",Toast.LENGTH_SHORT).show();
savetheinfo();
}
else{
Toast.makeText(RegisterActivity.this,"Could not registered , please try again...",Toast.LENGTH_SHORT).show();
}
}
});
}
private void savetheinfo() {
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
.setDisplayName(String.valueOf(mNameEditText)).build();
user.updateProfile(profileUpdates);
}
}
public class ProfileActivity extends AppCompatActivity {
@BindView(R.id.user_name) TextView mUserName;
private FirebaseAuth mAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
ButterKnife.bind(this);
mAuth = FirebaseAuth.getInstance();
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
setDataToView(user);
}
private void setDataToView(FirebaseUser user) {
mUserName.setText(user.getDisplayName());
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="24dp"
android:text="REGISTER"
android:layout_marginBottom="50dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: "/>
<EditText
android:id="@+id/name_text"
android:layout_width="100dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Surname: "/>
<EditText
android:id="@+id/surname_edittext"
android:layout_width="100dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mail: "/>
<EditText
android:id="@+id/mail_edittext"
android:layout_width="100dp"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Password: "/>
<EditText
android:id="@+id/password_edittext"
android:layout_width="100dp"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="@+id/register_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Register"
android:layout_marginTop="50dp"/>
</LinearLayout>
最佳答案
如果视图不为空,则String.valueOf(mNameEditText)
等效于mNameEditText.toString()
。您可能正在寻找mNameEditText.getText().toString()
,它为您提供EditText
元素的内容。