How to dismiss AlertDialog in android

后端 未结 7 2162
忘掉有多难
忘掉有多难 2020-11-29 05:43

I created AlertDialog that contains 4 buttons

OptionDialog = new AlertDialog.Builder(this);
        OptionDialog.setTitle(\"Options\");
        LayoutInflat         


        
7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-29 06:22

    There are two ways of closing an alert dialog.

    Option 1:

    AlertDialog#create().dismiss();

    Option 2:

    The DialogInterface#dismiss();

    Out of the box, the framework calls DialogInterface#dismiss(); when you define event listeners for the buttons:

    1. AlertDialog#setNegativeButton();
    2. AlertDialog#setPositiveButton();
    3. AlertDialog#setNeutralButton();

    for the Alert dialog.

提交回复
热议问题