AlertDialog의 단추를 눌렀을 때 AlertDialog가 디스미스에서 떨어지지 않도록 하는 방법

2025 단어 AlertDialog
//  

@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); 

    }

좋은 웹페이지 즐겨찾기