本文介绍了AlertDialog setOnDismissListener不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的活动打开一个对话框.当它关闭时,我需要执行功能ReloadTable()
.所以我正在尝试使用setOnDismissListener
,但没有被触发.有人可以帮我做错什么吗?
My activity opens a dialog. When it closes I need the function ReloadTable()
to be executed. So I am trying to use setOnDismissListener
but its not getting triggered. Could someone please help what I am doing wrong?
谢谢!
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();
.....
}
}
这篇关于AlertDialog setOnDismissListener不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!