gpt4 book ai didi

java - android中的密码验证确认

转载 作者:太空宇宙 更新时间:2023-11-03 11:44:22 24 4
gpt4 key购买 nike

我有这个 Activity ,我想在其中验证确认密码字段。这是我的代码-:

nt.setOnClickListener(new OnClickListener() { 

public void onClick(View v) {

if(email.getText().toString().equals("")){
AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("E-mail field is empty");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
alertDialog.show();
}
else if(pass.getText().toString().equals("")){

AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("Password field is empty");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});

alertDialog.show();
}

else if(conpass.getText().toString()!= pass.getText().toString() ){
AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("Passwords do not match");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
alertDialog.show();
}
else if(name.getText().toString().equals("")){
AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("Name field is empty");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
alertDialog.show();
}
else if(dob.getText().toString().equals("")){
AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("Date of birth field is empty");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
alertDialog.show();
}
else if(address.getText().toString().equals("")){
AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("Address field is empty");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
alertDialog.show();
}
else if(city.getText().toString().equals("")){
AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("City field is empty");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
alertDialog.show();
}
else if(zip.getText().toString().equals("")){
AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("Zip field is empty");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
alertDialog.show();
}
else if(phone.getText().toString().equals("")){
AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("Phone No. field is empty");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
alertDialog.show();
}
else if(mobile.getText().toString().equals("")){
AlertDialog alertDialog = new AlertDialog.Builder(Registration.this).create();
alertDialog.setTitle("oops!");
alertDialog.setMessage("Mobile No field is empty");
alertDialog.setButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//dismiss the dialog
}
});
alertDialog.show();
}

else{

String mail = email.getText().toString();

String pas = pass.getText().toString();

String fname = name.getText().toString();

String dateob = dob.getText().toString();

String add12 = address.getText().toString();

String tow = city.getText().toString();

String zip1 = zip.getText().toString();

String mob = mobile.getText().toString();

String phn = phone.getText().toString();

Intent per = new Intent(getApplicationContext(), Register2.class);
per.putExtra("email", mail);
per.putExtra("name", fname);
per.putExtra("password", pas);
per.putExtra("mobile", mob);
per.putExtra("phone", phn);
per.putExtra("address", add12);
per.putExtra("zip", zip1);
per.putExtra("city", tow);
per.putExtra("dateofbirth", dateob);
startActivity(per);
}

}
});

现在即使我的两个 edittext 字段相同,它仍然显示密码不匹配的警告对话框。请在这里帮助我。提前致谢。

最佳答案

您不能使用=!= 来比较字符串,而是使用equals

else if(!conpass.getText().toString().equals(pass.getText().toString()) )

关于java - android中的密码验证确认,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16030806/

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