AlertDialog 点击按钮后不关闭的处理办法
发布日期:2021-06-30 18:38:55 浏览次数:2 分类:技术文章

本文共 1347 字,大约阅读时间需要 4 分钟。

AlertDialog 点击按钮后不关闭的处理办法

new AlertDialog.Builder( this ).setPositiveButton( new String( "确定" ),     new DialogInterface.OnClickListener() {        @Override        public void         onClick( DialogInterface dialog,                  int             which )        {            if ( 判断条件 )            {                // 条件不成立不能关闭 AlertDialog 窗口                try                 {                    Field field = dialog.getClass().getSuperclass().getDeclaredField( "mShowing" );                    field.setAccessible( true );                    field.set( dialog,                                false ); // false - 使之不能关闭(此为机关所在,其它语句相同)                }                 catch ( Exception e )                 {                    Log.e( e.getMessage() );                    e.printStackTrace();                }            }             else             {                // 条件成立能关闭 AlertDialog 窗口                try                 {                    Field field = dialog.getClass().getSuperclass().getDeclaredField( "mShowing" );                    field.setAccessible( true );                    field.set( dialog,                                true ); // true - 使之可以关闭(此为机关所在,其它语句相同)                }                catch (Exception e)                 {                    e.printStackTrace();                }            }        }    }

转载地址:https://linqiarui.blog.csdn.net/article/details/51049199 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Android开发——自动连接指定SSID的wifi热点(不加密/加密)
下一篇:android重新启动应用程序和重新启动系统

发表评论

最新留言

能坚持,总会有不一样的收获!
[***.219.124.196]2024年04月12日 11时59分44秒