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

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

                            new AlertDialog.Builder(context)
                                    // 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) {

                        } else {
                            if(idCustomer != 0) {
                                idCustomer = 0;
                }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 *