-1

I have taken a custom dialog with edittext on it to enter OTP. I have check whether OTP entered is correct or not. I also want to show toast message if no OTP is entered in edittext but the dialog opened should remain opened. Below is my code

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();
Nandkishor mewara
  • 2,552
  • 16
  • 29
Abhilash Harsole
  • 244
  • 2
  • 4
  • 15

3 Answers3

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();
    }

You wanted to show A Toast then it ll help!!!

Nandkishor mewara
  • 2,552
  • 16
  • 29
Mr.Popular
  • 845
  • 1
  • 8
  • 15
  • the custom dialog opened should remain opened after showing the no otp is entered toast. – Abhilash Harsole Dec 23 '16 at 09:47
  • AlertDialog will be canceled if you click anyone of the buttons if you want your dialog keep opened then you can show a Dialog with inflated view in it. It will show You Exact Bhaviour you want – Mr.Popular Dec 23 '16 at 10:12
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();
Nandkishor mewara
  • 2,552
  • 16
  • 29
Kush Patel
  • 1,228
  • 1
  • 13
  • 34
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();
    }
Nandkishor mewara
  • 2,552
  • 16
  • 29
Rajakumar
  • 907
  • 1
  • 7
  • 17