lum*_*ire 11 android android-alertdialog
我的活动打开一个对话框.当它关闭时,我需要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();
Run Code Online (Sandbox Code Playgroud)
Zee*_*v G 10
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();
.....
}
}
Run Code Online (Sandbox Code Playgroud)
小智 6
您必须将setOnCancelListener设置为AlertDialog.Builder:
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
this);
alertDialogBuilder.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
dialogmenu = false;
}
})
Run Code Online (Sandbox Code Playgroud)
在这种情况下,您应该使用alertDialog.setOnCancelListener(listener),andalertDialog.setOnDismissListener与 一起使用dismissDialog(id)。
| 归档时间: |
|
| 查看次数: |
29234 次 |
| 最近记录: |