Monday, August 6, 2012

how to catch the dialog dismiss

It is a very simple example and I just want to put here because many AlertDialog example doesn't mention this.

AlertDialog al = new AlertDialog.Builder(this)
.setTitle("Title")
.setSingleChoiceItems(adapter, 0, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
        //do something when pressing the list item.
    }
})
.setPositiveButton("Done", new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int whichButton) {
        //do something when pressing the Done button.
    }
}).create();
al.show();
al.setOnDismissListener(new OnDismissListener() {          
    @Override
    public void onDismiss(DialogInterface dialog) {
      //do something when the dialog dismiss.
    }
});

No comments:

Post a Comment

You can leave any question here and I will make a response to you ASAP. :D