zoukankan      html  css  js  c++  java
  • 4.19

    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
    
        private Button btn_dialog_one;
        private Button btn_dialog_two;
        private Button btn_dialog_three;
        private Button btn_dialog_four;
    
        private Context mContext;
        private boolean[] checkItems;
    
        private AlertDialog alert = null;
        private AlertDialog.Builder builder = null;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            mContext = MainActivity.this;
            bindView();
    
    
        }
    
        private void bindView() {
            btn_dialog_one = (Button) findViewById(R.id.btn_dialog_one);
            btn_dialog_two = (Button) findViewById(R.id.btn_dialog_two);
            btn_dialog_three = (Button) findViewById(R.id.btn_dialog_three);
            btn_dialog_four = (Button) findViewById(R.id.btn_dialog_four);
            btn_dialog_one.setOnClickListener(this);
            btn_dialog_two.setOnClickListener(this);
            btn_dialog_three.setOnClickListener(this);
            btn_dialog_four.setOnClickListener(this);
        }
    
    
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                //普通对话框
                case R.id.btn_dialog_one:
                    alert = null;
                    builder = new AlertDialog.Builder(mContext);
                    alert = builder.setIcon(R.mipmap.ic_icon_fish)
                            .setTitle("系统提示:")
                            .setMessage("这是一个最普通的AlertDialog,
    带有三个按钮,分别是取消,中立和确定")
                            .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Toast.makeText(mContext, "你点击了取消按钮~", Toast.LENGTH_SHORT).show();
                                }
                            })
                            .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Toast.makeText(mContext, "你点击了确定按钮~", Toast.LENGTH_SHORT).show();
                                }
                            })
                            .setNeutralButton("中立", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    Toast.makeText(mContext, "你点击了中立按钮~", Toast.LENGTH_SHORT).show();
                                }
                            }).create();             //创建AlertDialog对象
                    alert.show();                    //显示对话框
                    break;
                //普通列表对话框
                case R.id.btn_dialog_two:
                    final String[] lesson = new String[]{"语文", "数学", "英语", "化学", "生物", "物理", "体育"};
                    alert = null;
                    builder = new AlertDialog.Builder(mContext);
                    alert = builder.setIcon(R.mipmap.ic_icon_fish).setTitle("选择你喜欢的课程").setItems(lesson,newDialogInterface.OnClickListener(){@Overridepublicvoid onClick(DialogInterface dialog,int which){Toast.makeText(getApplicationContext(),"你选择了"+ lesson[which],Toast.LENGTH_SHORT).show();}}).create();
                    alert.show();break;//单选列表对话框case R.id.btn_dialog_three:finalString[] fruits =newString[]{"苹果","雪梨","香蕉","葡萄","西瓜"};
                    alert =null;
                    builder =newAlertDialog.Builder(mContext);
                    alert = builder.setIcon(R.mipmap.ic_icon_fish).setTitle("选择你喜欢的水果,只能选一个哦~").setSingleChoiceItems(fruits,0,newDialogInterface.OnClickListener(){@Overridepublicvoid onClick(DialogInterface dialog,int which){Toast.makeText(getApplicationContext(),"你选择了"+ fruits[which],Toast.LENGTH_SHORT).show();}}).create();
                    alert.show();break;//多选列表对话框case R.id.btn_dialog_four:finalString[] menu =newString[]{"水煮豆腐","萝卜牛腩","酱油鸡","胡椒猪肚鸡"};//定义一个用来记录个列表项状态的boolean数组
                    checkItems =newboolean[]{false,false,false,false};
                    alert =null;
                    builder =newAlertDialog.Builder(mContext);
                    alert = builder.setIcon(R.mipmap.ic_icon_fish).setMultiChoiceItems(menu, checkItems,newDialogInterface.OnMultiChoiceClickListener(){@Overridepublicvoid onClick(DialogInterface dialog,int which,boolean isChecked){
                                    checkItems[which]= isChecked;}}).setPositiveButton("确定",newDialogInterface.OnClickListener(){@Overridepublicvoid onClick(DialogInterface dialog,int which){String result ="";for(int i =0; i < checkItems.length; i++){if(checkItems[i])
                                            result += menu[i]+" ";}Toast.makeText(getApplicationContext(),"客官你点了:"+ result,Toast.LENGTH_SHORT).show();}}).create();
                    alert.show();break;}}}
  • 相关阅读:
    保证测试通过的ip正则,antdIP/IP段的校验方法,antd的textArea中可以输入多个以换行分隔的ip/IP段,并自动检测出错行的原因
    TP5接口出错只能返回500
    UDP服务只能本机访问问题
    有出现了找半天的小BUG
    PHP本地安装redis扩展
    MYSQL数据库和es数据库同步
    QQ互联应用申请失败
    axios跨域问题解决
    elastic和kibana安装心得
    自增运算符理解
  • 原文地址:https://www.cnblogs.com/20193898liufa/p/14909589.html
Copyright © 2011-2022 走看看