zoukankan      html  css  js  c++  java
  • android 的AlertDialog对话框

     
     
     private int selectedFruitIndex = 0; 
     private void showMsg2()
     {
    //  Dialog alertDialog = new AlertDialog.Builder(this).  
    //                setTitle("确定删除?").  
    //                setMessage("您确定删除该条信息吗?").  
    //                setIcon(R.drawable.ic_launcher).  
    //                setPositiveButton("确定", new DialogInterface.OnClickListener() {  
    //                      
    //                    @Override  
    //                    public void onClick(DialogInterface dialog, int which) {  
    //                        // TODO Auto-generated method stub   
    //                    }  
    //                }).  
    //                setNegativeButton("取消", new DialogInterface.OnClickListener() {  
    //                      
    //                    @Override  
    //                    public void onClick(DialogInterface dialog, int which) {  
    //                        // TODO Auto-generated method stub   
    //                    }  
    //                }).  
    //                setNeutralButton("查看详情", new DialogInterface.OnClickListener() {  
    //                      
    //                    @Override  
    //                    public void onClick(DialogInterface dialog, int which) {  
    //                        // TODO Auto-generated method stub   
    //                    }  
    //                }).  
    //                create();  
    //        alertDialog.show();  
      
    //  final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };  
    //    
    //        Dialog alertDialog = new AlertDialog.Builder(this).  
    //                setTitle("你喜欢吃哪种水果?").  
    //                setIcon(R.drawable.ic_launcher)
    //                .setItems(arrayFruit, new DialogInterface.OnClickListener() {  
    //   
    //                    @Override  
    //                    public void onClick(DialogInterface dialog, int which) {  
    //                        Toast.makeText(PubMainActivity.this, arrayFruit[which], Toast.LENGTH_SHORT).show();  
    //                    }  
    //                }).  
    //                setNegativeButton("取消", new DialogInterface.OnClickListener() {  
    //  
    //                    @Override  
    //                    public void onClick(DialogInterface dialog, int which) {  
    //                        // TODO Auto-generated method stub   
    //                    }  
    //                }).  
    //                create();  
    //        alertDialog.show();
      
      
    //        final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };  
    //       
    //        Dialog alertDialog = new AlertDialog.Builder(this).  
    //                setTitle("你喜欢吃哪种水果?").  
    //                setIcon(R.drawable.ic_launcher)
    //                .setSingleChoiceItems(arrayFruit, 0, new DialogInterface.OnClickListener() {  
    //   
    //                    @Override  
    //                    public void onClick(DialogInterface dialog, int which) {  
    //                        selectedFruitIndex = which;  
    //                    }  
    //                }).  
    //                setPositiveButton("确认", new DialogInterface.OnClickListener() {  
    //  
    //                    @Override  
    //                    public void onClick(DialogInterface dialog, int which) {  
    //                        Toast.makeText(PubMainActivity.this, arrayFruit[selectedFruitIndex], Toast.LENGTH_SHORT).show();  
    //                    }  
    //                }).  
    //                setNegativeButton("取消", new DialogInterface.OnClickListener() {  
    //  
    //                    @Override  
    //                    public void onClick(DialogInterface dialog, int which) {  
    //                        // TODO Auto-generated method stub   
    //                    }  
    //                }).  
    //                create();  
    //        alertDialog.show();  
     
      
            final String[] arrayFruit = new String[] { "苹果", "橘子", "草莓", "香蕉" };  
            final boolean[] arrayFruitSelected = new boolean[] {true, true, false, false};  
      
            //
    //        LayoutInflater factory = LayoutInflater.from(PubMainActivity.this);
    //        //获得自定义对话框
    //        View view = factory.inflate(R.layout.item_listitem, null);

           
            Dialog alertDialog = new AlertDialog.Builder(this).  
                    setTitle("你喜欢吃哪种水果?").  
                    setIcon(R.drawable.ic_launcher)
                    .setMultiChoiceItems(arrayFruit, arrayFruitSelected, new DialogInterface.OnMultiChoiceClickListener() {  
                          
                        @Override  
                        public void onClick(DialogInterface dialog, int which, boolean isChecked) {  
                            arrayFruitSelected[which] = isChecked;  
                        }  
                    }).  
                    setPositiveButton("确认", new DialogInterface.OnClickListener() {  
      
                        @Override  
                        public void onClick(DialogInterface dialog, int which) {  
                            StringBuilder stringBuilder = new StringBuilder();  
                            for (int i = 0; i < arrayFruitSelected.length; i++) {  
                                if (arrayFruitSelected[i] == true)  
                                {  
                                    stringBuilder.append(arrayFruit[i] + "、");  
                                }  
                            }  
                            Toast.makeText(PubMainActivity.this, stringBuilder.toString(), Toast.LENGTH_SHORT).show();  
                        }  
                    }).  
                    setNegativeButton("取消", new DialogInterface.OnClickListener() {  
      
                        @Override  
                        public void onClick(DialogInterface dialog, int which) {  
                            // TODO Auto-generated method stub   
                        }  
                    }).  
                    create();  
            alertDialog.show();     
     }

  • 相关阅读:
    Python练习(二) 4位数四则运算
    Python 练习题之一回文数
    uniapp小程序request请求封装
    uniapp小程序微信一键登录实现过程记录
    Oralce EBS R12 FORM显示配色方案
    PLSQL Developer 连接远程数据库 OCI客户端安装方法
    XFire中Services.xml 配置的一些细节
    Oracle EBS 报表输出字符字段前部"0"被Excel自动去掉问题
    Eclipse Java EE IDE 中使用Tomcat 5X / 6X 的一些问题(配置,发布相关)
    BI Publisher Desktop 安装错误 Template Builder Installer Failed: Unexpected Error
  • 原文地址:https://www.cnblogs.com/zmc/p/3655655.html
Copyright © 2011-2022 走看看