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

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();
                }
            }
        }
    }


你可能感兴趣的:(AlertDialog 点击按钮后不关闭的处理办法)