alertdialog 自定义view 以及反射

      View  view = (LinearLayout) getLayoutInflater().inflate(R.layout.outlayout,null);
            AlertDialog.Builder builder =new AlertDialog.Builder(DataActivity1.this);
            builder.setTitle("导出数据");
            builder.setView(view);


            final EditText 文件名 = (EditText)view.findViewById(R.id.fileName);
            文件名.setText(nowTime);
                    //相当于点击确认按钮
            builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {

                            String fileName = 文件名.getText() + "";
                            if (fileName.length() < 1){
                                try {
                                    Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
                                    field.setAccessible(true);
                                    field.set(dialog, false);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }else{
                                try {
                                    Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
                                    field.setAccessible(true);
                                    field.set(dialog, true);
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }


                                ExcelOperTest ex = new ExcelOperTest();
                                try {
                                    ex.DataWrite2Excel(DataActivity1.dataList,fileName + ".xls");
                                    Toast.makeText(DataActivity1.this, "导出成功!",
                                            Toast.LENGTH_SHORT).show();
                                } catch (IOException e) {
                                    e.printStackTrace();
                                    Toast.makeText(DataActivity1.this, "导出失败!",
                                            Toast.LENGTH_SHORT).show();
                                } catch (WriteException e) {
                                    e.printStackTrace();
                                    Toast.makeText(DataActivity1.this, "导出失败!",
                                            Toast.LENGTH_SHORT).show();
                                }
                            }

                        }
                    });
    //相当于点击取消按钮
            builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
    // TODO Auto-generated method stub


                        }
                    });

            builder.create();
            builder.show();

//布局






    

        
            


            
        


    


你可能感兴趣的:(alertdialog 自定义view 以及反射)