Dismiss a custom dialog?

后端 未结 4 1346
独厮守ぢ
独厮守ぢ 2020-12-11 03:43

I\'m trying to make a custom dialog to show a view in this dialog. This is the Builder code:

//Getting the layout
LayoutInflater inflater = (LayoutInflater)          


        
相关标签:
4条回答
  • 2020-12-11 03:43

    I think a better way may be to call

    dismissDialog(DIALOG_ID);
    

    Wouldn't making the AlertDialog a class property defeat the purpose of returning a Dialog from the onCreateDialog()?

    0 讨论(0)
  • 2020-12-11 03:54

    Use AlertDialog instance e.g. mAlertDialog as a global variable. And call mAlertDialog.dismiss(); inside onClick()

    0 讨论(0)
  • 2020-12-11 03:58

    You have to save the AlertDialog to your parent class property, then use something like this:

    class parentClass ........ {
    private AlertDialog alert=null;
    ........
    public void onClick(View v) {
            //Do some stuff
    
            //Here i want to close the dialog
            if (parentClass.this.alert!=null)            
            parentClass.this.alert.dismiss();
        }
    ........
    this.alert = builder.create();
    this.alert.show();
    

    }

    0 讨论(0)
  • 2020-12-11 04:10

    ı am using

    public  Dialog dialog;
    
    buton_sil.setOnClickListener(new View.OnClickListener() {
    
                @ Override
                public void onClick(View v) {
    
                       DialogClose();
                       }
    }):
    
    
    public void DialogClose() {
            dialog.dismiss();
        }
    
    0 讨论(0)
提交回复
热议问题