android - AlertDialog setOnDismissListener 不工作

标签 android android-alertdialog

我的 Activity 打开了一个对话框。当它关闭时,我需要执行函数 ReloadTable()。所以我正在尝试使用 setOnDismissListener 但它没有被触发。有人可以帮助我做错什么吗?

谢谢!

AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.transaction, null);
builder = new AlertDialog.Builder(new ContextThemeWrapper(TransactionsList.this , R.style.dialogwithoutdim));
builder.setView(layout);
alertDialog = builder.create();
alertDialog.setOnDismissListener(new OnDismissListener() {
    public void onDismiss(final DialogInterface dialog) {
        ReloadTable();
    }
});

builder.show();

最佳答案

public class MyActivity extends Activity implements DialogInterface.OnCancelListener{
    @Override
    public void onCreate(Bundle state) {
       .....
       alertDialog.setOnCancelListener(this);
       alertDialog.show();
    }
    @Override
    public void onCancel(DialogInterface dialog) {
        dialog.dismiss();
        .....
    }
}

关于android - AlertDialog setOnDismissListener 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12525304/

相关文章:

android - 在通话中暂停音乐播放器,并在 android 通话后再次恢复播放器

android - Android 上的 Soundfonts

android - Android 上的 Video.js?它有效吗?

android - NumberPicker onValueChange 未被调用

android - Material 成分确认对话框

java - 正则表达式从歌曲名称中删除轨道编号?

Android 在 Dialog 中覆盖 onKeyDown

android - 处理 AlertDialog.Builder 中的后退按钮

android - 多次使用相同的 AlertDialog 框并更改一个变量

android - 有没有办法防止 AlertDialog 因输入无效而关闭?