gpt4 book ai didi

java - 即使密码和确认密码匹配,也会出现 Toast 消息

转载 作者:行者123 更新时间:2023-12-01 10:08:50 25 4
gpt4 key购买 nike

package com.example.chris.thegiver;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class RegisterActivity extends AppCompatActivity {
// calls the constructor of the DatabaseHelper class which will create the database and table
DatabaseHelper registerDB = new DatabaseHelper(this);

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
}

public void onRegisterClick(View v) {
if (v.getId() == R.id.btnReg) {

EditText etName = (EditText) findViewById(R.id.etName);
EditText etEmail = (EditText) findViewById(R.id.etEmail);
EditText etUsername = (EditText) findViewById(R.id.etUsername);
EditText etPassword = (EditText) findViewById(R.id.etUsername);
EditText etConfirm = (EditText) findViewById(R.id.etConfirm);


String name = etName.getText().toString();
String email = etEmail.getText().toString();
String user = etUsername.getText().toString();
String password = etPassword.getText().toString();
String confirm = etConfirm.getText().toString();

if (password.equals(confirm)) {
Contact c = new Contact();
c.setName(name);
c.setEmail(email);
c.setUsername(user);
c.setPassword(password);

registerDB.insertContact(c);
}
else {
// Pop up message It skips the original if statement for some reason
Toast pass = Toast.makeText(RegisterActivity.this, "Passwords Dont Match!", Toast.LENGTH_SHORT);
pass.show();
}

}
}
}

最佳答案

根据提供的代码,唯一可能的原因是以下两个之一:

EditText etPassword = (EditText) findViewById(R.id.etUsername);
EditText etConfirm = (EditText) findViewById(R.id.etConfirm);

这些 ID 并不像他们所说的那样。检查 xml 布局并确保这两个 edittext id 实际上是您认为的那样。例如,您可能由于复制粘贴而交换了用户名密码 ID,但没有注意到。

或者:您添加了空格,虽然您没有看到它,但文本确实不同

编辑:刚刚更加仔细地检查过。问题出在这里:

EditText etPassword = (EditText) findViewById(R.id.etUsername);
EditText etConfirm = (EditText) findViewById(R.id.etConfirm);

原因一已确认

关于java - 即使密码和确认密码匹配,也会出现 Toast 消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36293594/

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