zoukankan      html  css  js  c++  java
  • 如何使当点击AlertDialog中的按钮时,AlertDialog不被dismiss掉

    //通过反射来实现 
    @Override 
        protected Dialog onCreateDialog(int id) { 
            final AlertDialog.Builder builder=new AlertDialog.Builder(this); 
            if(id==1){ 
                builder.setTitle("标题"); 
                builder.setMessage("消息"); 
                final EditText et = new EditText(this); 
                et.setWidth(LayoutParams.FILL_PARENT); 
                et.setPadding(5, 5 ,5, 5); 
                et.setTextSize(18); 
                et.setHeight(160); 
                et.setGravity(Gravity.TOP); 
                builder.setView(et); 
                final AlertDialog ad = builder.create(); 
                ad.setButton("确定", new DialogInterface.OnClickListener(){ 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        if(et.getText().toString().trim().length()==0){ 
                            try { 
                                Field field = ad.getClass().getSuperclass() 
                                        .getDeclaredField("mShowing"); 
                                field.setAccessible(true); 
                                field.set(ad, false); 
                            } catch (Exception e) { 
                                e.printStackTrace(); 
                            } 
                        } 
                    }}); 
                ad.setButton2("取消",new DialogInterface.OnClickListener(){ 
                    @Override 
                    public void onClick(DialogInterface dialog, int which) { 
                        try { 
                            Field field = ad.getClass().getSuperclass() 
                                    .getDeclaredField("mShowing"); 
                            field.setAccessible(true); 
                            field.set(ad, true); 
                        } catch (Exception e) { 
                            e.printStackTrace(); 
                        } 
                    }}); 
    
                return ad; 
            } 
            return super.onCreateDialog(id); 
        }
  • 相关阅读:
    Linux系统常见的压缩与打包
    java 语言规范 java language specifications
    java 枚举
    github邮箱验证技巧
    关于 python
    博客园 编程基础 精华
    fiddler
    一个牛人写的博客
    使用xmarks同步 chrome ie firefox safari书签
    linux 中的 tar 解压
  • 原文地址:https://www.cnblogs.com/ihou/p/2092432.html
Copyright © 2011-2022 走看看