[英]How to Validate method on button click
在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();
}
}
}
用這個:
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();
}
在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();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.