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

  • 相关阅读:
    POJ 1451
    LightOJ 1224
    POJ 2001
    HDU 2072
    POJ 3764
    CH 1602
    CH 1601
    Gym 101873K
    CH 1201
    Gym 101873C
  • 原文地址:https://www.cnblogs.com/zmc/p/3655655.html
Copyright © 2011-2022 走看看