gpt4 book ai didi

android - 密码和 ConfirmPassword 验证 Android 不工作

转载 作者:行者123 更新时间:2023-11-29 15:17:46 24 4
gpt4 key购买 nike

我有两个页面。我正在尝试通过 Bundle 传递 Password 字段值,并使用 ConfirmPassword 字段检查此值。验证无效。我可以知道什么是实现我的目标的正确方法吗?也许这个问题太基础了,但我没有找到任何合适的解决方案。请帮助我。

这是我的代码:

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

EditTextUserPass= (EditText) findViewById(R.id.UserHiddenPass);
EditTextUserPass.setVisibility(View.GONE);

Imagepassone = (ImageButton) findViewById(R.id.ButtonPassOne);
Imagepasstwo = (ImageButton) findViewById(R.id.ButtonPassTwo);

Imagepassone.setOnClickListener(imgButtonHandlerone);
Imagepasstwo.setOnClickListener(imgButtonHandlertwo);


image = (ImageView) findViewById(R.id.imagefirstpasscode);
image2 = (ImageView) findViewById(R.id.imagesecondpasscode);
image3=(ImageView)findViewById(R.id.imagethirdpasscode);
image4=(ImageView)findViewById(R.id.imagefourpasscode);

}


View.OnClickListener imgButtonHandlerone = new View.OnClickListener() {


public void onClick(View v) {

if(v.getId() == R.id.ButtonPassOne) {

nbStep++;

changeStepBackground(nbStep);
}
}
};
public void changeStepBackground(int i) {
// four step switch
switch(i) {
case 1:
image.setImageResource(R.drawable.passselect);
EditTextUserPass.setText("1");

break;
case 2:
image2.setImageResource(R.drawable.passselect);
EditTextUserPass.setText("1");
break;
case 3:
image3.setImageResource(R.drawable.passselect);
EditTextUserPass.setText("1");
break;
case 4:
image4.setImageResource(R.drawable.passselect);
EditTextUserPass.setText("1");
break;


}
}

View.OnClickListener imgButtonHandlertwo = new View.OnClickListener() {



public void onClick(View v) {

if(v.getId() == R.id.ButtonPassTwo) {

nbStep++;

changeStepBackground2(nbStep);
}
}
};
public void changeStepBackground2(int i) {

switch(i) {
case 1:
image.setImageResource(R.drawable.passselect);
EditTextUserPass.setText("2");
break;
case 2:
image2.setImageResource(R.drawable.passselect);
EditTextUserPass.setText("2");
break;
case 3:
image3.setImageResource(R.drawable.passselect);
EditTextUserPass.setText("2");
break;
case 4:
image4.setImageResource(R.drawable.passselect);
EditTextUserPass.setText("2");
break;


}
}

}
@Override
public void onBackPressed() {
moveTaskToBack(true);
UserPasscode.this.finish();
}

public void gotoconfirmpasscode(View v)

{
String UserPass=EditTextUserPass.getText().toString();
int numberOfImages=nbStep;
if(numberOfImages!=4)
{
}
else
{

Bundle b = new Bundle();
b.putString("PASSWORD", UserPass);

Intent intent = new Intent(UserPasscode.this,UserConfirmPasscode .class);
intent.putExtras(b);
startActivity(intent);
}

}
}

第二页:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_user_confirm_passcode);
EditTextUserConfirmPass= (EditText) findViewById(R.id.UserHiddenConfirmPass);
EditTextUserPass= (EditText) findViewById(R.id.UserHiddenPass);
EditTextUserConfirmPass.setVisibility(View.GONE);

UserHiddenConfirmPass2= (EditText) findViewById(R.id.UserHiddenConfirmPass2);
UserHiddenConfirmPass2.setVisibility(View.GONE);

Imagepassone = (ImageButton) findViewById(R.id.ButtonPassOne);
Imagepasstwo = (ImageButton) findViewById(R.id.ButtonPassTwo);

Imagepassone.setOnClickListener(imgButtonHandlerone);
Imagepasstwo.setOnClickListener(imgButtonHandlertwo);


image = (ImageView) findViewById(R.id.imagefirstpasscode);
image2 = (ImageView) findViewById(R.id.imagesecondpasscode);
image3=(ImageView)findViewById(R.id.imagethirdpasscode);
image4=(ImageView)findViewById(R.id.imagefourpasscode);
}

View.OnClickListener imgButtonHandlerone = new View.OnClickListener() {


public void onClick(View v) {

if(v.getId() == R.id.ButtonPassOne) {

nbStep++;

changeStepBackground(nbStep);
}
}
};
public void changeStepBackground(int i) {
// four step switch
switch(i) {
case 1:
image.setImageResource(R.drawable.passselect);
EditTextUserConfirmPass.setText("1");
break;
case 2:
image2.setImageResource(R.drawable.passselect);
EditTextUserConfirmPass.setText("1");
break;
case 3:
image3.setImageResource(R.drawable.passselect);
EditTextUserConfirmPass.setText("1");
break;
case 4:
image4.setImageResource(R.drawable.passselect);
EditTextUserConfirmPass.setText("1");
break;


}
}

View.OnClickListener imgButtonHandlertwo = new View.OnClickListener() {



public void onClick(View v) {

if(v.getId() == R.id.ButtonPassTwo) {

nbStep++;

changeStepBackground2(nbStep);
}
}
};
public void changeStepBackground2(int i) {

switch(i) {
case 1:
image.setImageResource(R.drawable.passselect);
EditTextUserConfirmPass.setText("2");
break;
case 2:
image2.setImageResource(R.drawable.passselect);
EditTextUserConfirmPass.setText("2");
break;
case 3:
image3.setImageResource(R.drawable.passselect);
EditTextUserConfirmPass.setText("2");
break;
case 4:
image4.setImageResource(R.drawable.passselect);
EditTextUserConfirmPass.setText("2");
break;


}
}
}

public void gotoMain(View v)
{
Bundle b = getIntent().getExtras();
String venName = b.getString("PASSWORD");
UserHiddenConfirmPass2.setText(venName);

Bundle c = new Bundle();
String UserPass=c.getString("CONFIRMPASSWORD");
EditTextUserConfirmPass.setText(UserPass);

c.putString("CONFIRMPASSWORD", EditTextUserConfirmPass.getText().toString());

int numberOfImages=nbStep;
if(numberOfImages!=4 )
{
}

if(!venName.equals(UserPass)){

}

else{

Intent intent = new Intent(this,MainActivity .class);
startActivity(intent);
}
}
}

最佳答案

字符串比较错误。始终将 String 与 .equals() 方法进行比较。改变这个:

if(venName!=UserPass)

为此:

System.out.println("venName :: "+venName);
System.out.println("UserPass :: "+UserPass);
if(!venName.equals(UserPass))

关于android - 密码和 ConfirmPassword 验证 Android 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22658626/

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