在 ComparingValues(); 方法中,我比较了TextViews的值,但现在我需要使用按钮点击来验证我的方法....
如果在 ComparingValues(); 方法上 发现所有三个匹配 ,我需要调用: -
Toast.makeText(getApplicationContext(), "Logged In", Toast.LENGTH_SHORT).show();
否则
Toast.makeText(getApplicationContext(), "Cannot Continue", Toast.LENGTH_SHORT).show();
查看我的代码:
btnLicenseCheck = (Button) findViewById(R.id.btnLicenseCheck);
btnLicenseCheck.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// if all 3 matches found then need to show
// Toast.makeText(getApplicationContext(), "Logged In", Toast.LENGTH_SHORT).show();
// else
// Toast.makeText(getApplicationContext(), "Cannot Continue", Toast.LENGTH_SHORT).show();
LicenseValidation();
}
});
}
public void ComparingValues()
{
editPassword = (EditText) findViewById(R.id.editPassword);
strPassword = editPassword.getText().toString();
/*** comparing password ***/
if(strPassword.equals(textPassword))
{
Toast.makeText(getApplicationContext(), "Password Match !",
Toast.LENGTH_SHORT).show();
editPassword.setText(null);
}
else
{
Toast.makeText(getApplicationContext(), "Password Does not match !",
Toast.LENGTH_SHORT).show();
}
/*** comparing deviceID ***/
if(strDeviceID.equals(textDeviceID))
{
Toast.makeText(getApplicationContext(), "DeviceID Match", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(), "DeviceID Does not match", Toast.LENGTH_SHORT).show();
}
/*** comparing emailID ***/
if(strEmailID.equals(textEmailID))
{
Toast.makeText(getApplicationContext(), "EmailID Match", Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(getApplicationContext(), "EmailID Does not match", Toast.LENGTH_SHORT).show();
}
}
}
答案 0 :(得分:1)
使用此:
if(strPassword.equals(textPassword) && strDeviceID.equals(textDeviceID) && strEmailID.equals(textEmailID))
{
Toast.makeText(getApplicationContext(), "Logged In", Toast.LENGTH_SHORT).show();
editPassword.setText(null);
}
else if(!strPassword.equals(textPassword))
{
Toast.makeText(getApplicationContext(), "Password Does not match !",
Toast.LENGTH_SHORT).show();
}
else if(!strDeviceID.equals(textDeviceID))
{
Toast.makeText(getApplicationContext(), "DeviceID Does not match", Toast.LENGTH_SHORT).show();
}
else if(strEmailID.equals(textEmailID))
{
Toast.makeText(getApplicationContext(), "EmailID Does not match", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "Cannot Continue", Toast.LENGTH_SHORT).show();
}
答案 1 :(得分:0)
在onclick里面做这个
if(strPassword.equals(textPassword)&&strDeviceID.equals(textDeviceID) && strEmailID.equals(textEmailID))
{
Toast.makeText(getApplicationContext(), "Logged In", Toast.LENGTH_SHORT).show();
}
else
Toast.makeText(getApplicationContext(), "Cannot Continue", Toast.LENGTH_SHORT).show();