Android-Dismiss/Hidedoesnotdismissthedialog
创始人
2024-08-19 18:00:05
0

问题描述:在Android应用程序中,当使用dismiss()或hide()方法时,有时对话框并不会被关闭或隐藏。 在使用dismiss()或hide()方法时,需要确保对话框已经完全创建并附加到Activity中。如果对话框尚未创建,或者已经被销毁,这些方法将不起作用,因此需要在对话框销毁前检查是否存在。

代码示例:

// 创建对话框 AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("提示") .setMessage("您确定要删除吗?") .setNegativeButton("取消", null) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { // 删除操作 // ... // 关闭对话框 if (dialogInterface != null) { dialogInterface.dismiss(); } } }); AlertDialog dialog = builder.create(); dialog.show();

// 检查对话框是否存在,并关闭 if (dialog != null && dialog.isShowing()) { dialog.dismiss(); }

相关内容

热门资讯

透视资料!德州局透视脚本(透视... 透视资料!德州局透视脚本(透视)菠萝德普辅助器免费版在哪里(辅助)确实真的是有脚本(哔哩哔哩)该软件...
透视课程!aapoker怎么拿... 透视课程!aapoker怎么拿好牌(HHpoker工具)总是真的是有辅助app(哔哩哔哩)1、点击下...
透视讲义!wejoker辅助器... 透视讲义!wejoker辅助器要钱玩吗(WPK方法)竟然存在有辅助脚本(哔哩哔哩)1、wejoker...
透视经验!hhpkoer辅助挂... 透视经验!hhpkoer辅助挂是真的吗(德普之星透视)其实真的是有辅助方法(哔哩哔哩)在进入hhpk...
透视大纲!pokemmo辅助脚... 透视大纲!pokemmo辅助脚本(透视)哈糖大菠萝怎么开挂(辅助)竟然有方法(哔哩哔哩)1)哈糖大菠...
透视手筋!pokemmo手机版... 透视手筋!pokemmo手机版脚本(透视)大菠萝789辅助器下载(辅助)总是是有神器(哔哩哔哩)1)...
透视资料!约局吧德州真的有透视... 透视资料!约局吧德州真的有透视挂吗(透视)智星菠萝透视(辅助)都是真的是有app(哔哩哔哩)1、很好...
透视方式!xpoker辅助控制... 透视方式!xpoker辅助控制(WePoKer简单)真是真的有辅助软件(哔哩哔哩)1、每一步都需要思...
透视法门!wepoker轻量版... 透视法门!wepoker轻量版有透视吗(WPK安卓)果然是有辅助技巧(哔哩哔哩)1、让任何用户在无需...
透视练习!大菠萝辅助器(透视)... 透视练习!大菠萝辅助器(透视)拱趴游戏破解器(辅助)一贯有神器(哔哩哔哩)1)拱趴游戏破解器有没有挂...