Antonio Costa
Antonio Costa

Reputation: 193

Alert Dialog builder doesn't have dismiss or cancel method

I know that there are lot of solutions currently to this question, but i couldn't solve with any of them. Actually i created a imageView and i set a listener to that imageView, i also created a custom builder to create my own alertDialog, what i need is to close the dialog when i click on the imageView so i did something like this:

final AlertDialog.Builder builder = new AlertDialog.Builder(Friends.this);
LayoutInflater inflater = Friends.this.getLayoutInflater();
                final View dialogView = inflater.inflate(R.layout.custom_builder, null);
close.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                    }
                });
 builder.show();

this is just part of my code, the builder.show is working fine, the close is the name of my imageView.

Thank you very much guys.

Upvotes: 1

Views: 302

Answers (1)

6155031
6155031

Reputation: 4327

you have to add builder.create() method for dismiss dialog. get an instance and dismiss it.

final AlertDialog.Builder builder = new AlertDialog.Builder(Friends.this);
    AlertDialog dialogInstance=builder.create();
    LayoutInflater inflater = Friends.this.getLayoutInflater();
                    final View dialogView = inflater.inflate(R.layout.custom_builder, null);
                        close.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                        dialogInstance.dismiss()
                        }
                    });
     builder.show();

happy coding :)

Upvotes: 2

Related Questions