gpt4 book ai didi

java - android.support.v7.widget.AppCompatEditText错误

转载 作者:行者123 更新时间:2023-12-01 20:10:48 24 4
gpt4 key购买 nike

错误:

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>

最佳答案

如果 View 不为空,

String.valueOf(mNameEditText) 相当于 mNameEditText.toString()。您可能正在寻找 mNameEditText.getText().toString(),它可以为您提供 EditText 元素的内容

关于java - android.support.v7.widget.AppCompatEditText错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46746775/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com