0

I have a class that extends from Dialog, that class is my Custom dialog. Now, what I have is a code that show the dialog, but it's executed in a OnClickListener of a button. The following code is my actual code:

colorpicker.setOnClickListener(new OnClickListener() {  
    @Override
    public void onClick(View v) {
        System.out.println("initial"+color);
        dialog = new ColorPickerDialog(Main.this, color);
        dialog.show();
        color=dialog.getfinalColor();
        System.out.println("Final"+color);
        drawView.changePaint(weight, color);
    }
});

Whant I want is to execute:

color=dialog.getfinalColor();
System.out.println("Final"+color);
drawView.changePaint(weight, color);

when the dialog is closed.

I try to do :

while(dialog.isShowing==true){
    color=dialog.getfinalColor();
    System.out.println("Final"+color);
    drawView.changePaint(weight, color);
}

But the app not crashes but don't do nothing, the app don't work fine with that code.

Any idea to make something like a onFinishDialogListener()?

4

1 回答 1

3

您可以使用setOnDismissListener()来注册一个回调,以便在您的对话框被关闭时。

然后你可以在这个回调中运行你的代码。

于 2013-04-26T17:44:35.740 回答