我已经使用edittext上的自定义对话框进入OTP。我检查输入的OTP是否正确。如果在edittext中没有输入OTP但是打开的对话框应保持打开状态,我还想显示toast消息。以下是我的代码
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int id){
enterOtp=edtEnterOtp.getText().toString().trim();
if(enterOtp.equals(randomNumber+"")){
sendWalletBallance();
}else{
Toast.makeText(MerchantPayment.this,"OTP Mismatch",Toast.LENGTH_LONG).show();
}
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int id){
dialog.cancel();
}
});
AlertDialog alertDialog=alertDialogBuilder.create();
alertDialog.show();
答案 0 :(得分:1)
if(enterOtp.equals(randomNumber+"")){
sendWalletBallance();
}else if(enterOtp.equals("")){
Toast.makeText(MerchantPayment.this,"no otp is entered ",Toast.LENGTH_LONG).show();
}else{
Toast.makeText(MerchantPayment.this,"OTP Mismatch",Toast.LENGTH_LONG).show();
}
你想展示一个祝酒词然后它会帮助!!!
答案 1 :(得分:0)
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int id){
enterOtp.setError(enterOtp.getText().toString().isEmpty()?mActivity.getString(R.string.title_error_message):null);
enterOtp.addTextChangedListener(new TextWatcher(){
@Override
public void onTextChanged(CharSequence s,int start,int before,int count){
}
@Override
public void beforeTextChanged(CharSequence s,int start,int count,int after){
}
@Override
public void afterTextChanged(Editable s){
enterOtp.setError(null);
}
});
if(enterOtp.getError()==null&&enterOtp.equals(randomNumber+"")){
sendWalletBallance();
}else{
Toast.makeText(MerchantPayment.this,"OTP Mismatch",Toast.LENGTH_LONG).show();
}
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int id){
dialog.cancel();
}
});
AlertDialog alertDialog=alertDialogBuilder.create();
alertDialog.show();
答案 2 :(得分:0)
if(etmobile.getText().toString().length()>0){
Toast.makeText(getApplicationContext(),"Its not empty",Toast.LENGTH_SHORT).show();
}else{
Toast.makeText(getApplicationContext(),"Its empty",Toast.LENGTH_SHORT).show();
}