我的 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/