Android Dialog, keep dialog open when button is pressed

后端 未结 7 1349
故里飘歌
故里飘歌 2020-11-30 01:59

I would like to keep my dialog open when I press a button. At the moment it\'s closing.

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder         


        
7条回答
  •  情深已故
    2020-11-30 02:38

    You can get the Dialog returned from method "show()" alertBuidler.

    AlertDialog.Builder adb = new AlertDialog.Builder(YourActivity.this);
    //...code to add methods setPositive an setNegative buttons
    

    Call the "show()" method of "adb" and get Dialog

    final AlertDialog dialog = adb.show();
    

    So you can call any button of your dialog at any point of code in your activity:

    dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();//or
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).performClick();//or
    dialog.getButton(DialogInterface.BUTTON_NEUTRAL).performClick();
    

提交回复
热议问题