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

  • 相关阅读:
    阿里--面经 搜集
    阿里一面经验总结
    System对象
    JDBC-oracle(登陆)
    博客静态页面
    设计模式(1)---Factory Pattern
    软件设计师备考经验(含新旧版本对比)
    第九课,ROS仿真1
    参数服务器相关的问题
    3.空域图像处理的洪荒之力
  • 原文地址:https://www.cnblogs.com/zmc/p/3655655.html
Copyright © 2020-2023  润新知