android – Alert dialog doesn't close at click of yes option-ThrowExceptions

Exception or error:

what I am trying to do is implement an alert dialog at the change of a edit text field. however I have to click on the yes option several times before it is close

@Override
            public void afterTextChanged(Editable s) {
                try {
                    if (!edtDocument1.getText().toString().trim().equals("")) {
                        int idDocumentTypeSelected1 = documentsTypeList.get(spnDocumentType1.getSelectedItemPosition()).idDocumentType;
                        Customer customerModel = new Customer().getCustomerByDocument(edtDocument1.getText().toString().trim(), idDocumentTypeSelected1);
                        if (customerModel != null) {
                            Toast.makeText(context, getString(R.string.customer_exist), Toast.LENGTH_SHORT).show();
                            setDataCustomersFinded(customerModel);

                            new AlertDialog.Builder(context)
                                    .setTitle(R.string.black_list_client)
                                    .setMessage(getString(R.string.black_list_client_id))
                                    // Specifying a listener allows you to take an action before dismissing the dialog.
                                    // The dialog is automatically dismissed when a dialog button is clicked.
                                    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int which) {
                                            backInitial();
                                        }
                                    })
                                    .setIcon(android.R.drawable.ic_dialog_alert)
                                    .show();

                        } else {
                            if(idCustomer != 0) {
                                idCustomer = 0;
                                cleanFormCustomer(false);
                            }
                        }
                    }
                }catch (Exception e){
                    Log.e(TAG, "afterTextChanged "+e);
                }
            }

Any help or suggestions would be great. thanks

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *