Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write onDismissListener to AlertDialog builder?

Tags:

android

Please see the code below.

final CharSequence[] cs = DeviceList.toArray(new CharSequence[DeviceList.size()]);
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setTitle("Pick the Item");

    builder.setItems(cs, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            //do something
        }

    });

    builder.show(); 

Some one please help me to implement a builder onDismissListener event in this code?

like image 680
Vineesh Avatar asked Apr 28 '16 06:04

Vineesh


1 Answers

Here you go:

builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {

        }
    });

So, the complete code will be something like:

final CharSequence[] cs = DeviceList.toArray(new CharSequence[DeviceList.size()]);
    AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
    builder.setTitle("Pick the Item");

    builder.setItems(cs, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            //do something
        }

    });
    builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {

        }
    });

    builder.show();
like image 143
Yasir Tahir Avatar answered Sep 28 '22 13:09

Yasir Tahir