简体   繁体   中英

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.

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM