在自定义对话框中检查 edittext 是否为空

Check if edittext is empty or not on custom dialog

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

你想祝酒词那么它会有所帮助!!!

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