zoukankan      html  css  js  c++  java
  • AlertDialog之常见对话框(单选对话框、多选对话框、进度条对话框)

    单选对话框,顾名思义就是只能选一项(setSingleChoiceItems(Items,))

     1 public void click(View v){
     2         //创建对话框类
     3         AlertDialog.Builder builder = new AlertDialog.Builder(this);
     4         //定义item选项
     5         final String items[] = new String[]{"一只","两只","三只"};
     6         builder.setTitle("没有什么事是一只口红解决不了的,如果有那就两只")//设置标题
     7                 .setSingleChoiceItems(items,-1, new DialogInterface.OnClickListener() {//设置单选
     8                     @Override
     9                     public void onClick(DialogInterface dialogInterface, int i) {
    10                         Toast.makeText(MainActivity.this,"你选择了用"+items[i]+"口红解决问题",Toast.LENGTH_SHORT).show();
    11                 }
    12                 }).setPositiveButton("是的", new DialogInterface.OnClickListener() {
    13             @Override
    14             public void onClick(DialogInterface dialogInterface, int i) {
    15                 Toast.makeText(MainActivity.this,"我选择了是",Toast.LENGTH_SHORT).show();
    16             }
    17         }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
    18             @Override
    19             public void onClick(DialogInterface dialogInterface, int i) {
    20                 Toast.makeText(MainActivity.this,"我选择了取消,因为我相信口红解决不了",Toast.LENGTH_SHORT).show();
    21             }
    22         }).show();
    23     }

     下面是多选对话框

     1 public void click1(View v){
     2         AlertDialog.Builder builder = new AlertDialog.Builder(this);
     3         final String items[] = {"First","Second","Thrid","Fourth"};
     4         final boolean boo[] = {true,false,false,false};
     5 
     6         builder.setTitle("人生有多种选择")
     7                 .setMultiChoiceItems(items, boo, new DialogInterface.OnMultiChoiceClickListener() {
     8                     @Override
     9                     public void onClick(DialogInterface dialogInterface, int i, boolean b) {
    10                       
    11                     }
    12                 }).setPositiveButton("确定", new DialogInterface.OnClickListener() {
    13             @Override
    14             public void onClick(DialogInterface dialogInterface, int i) {
    15 
    16             }
    17         }).show();
    18     }

    单选是setSingleChoiceItems(),多选是setMultiChoiceItems(),

    进度条对话框

     1 public void click2(View v){
     2         final ProgressDialog pd = new ProgressDialog(this);
     3         pd.setTitle("加载");
     4         pd.setProgress(0);
     5         pd.setMax(10);
     6         pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
     7         pd.show();
     8         new Thread(){
     9             @Override
    10             public void run() {
    11                 super.run();
    12                 for (int i=0; i<=10; i++){
    13                     pd.setProgress(i);
    14                     try {
    15                         Thread.sleep(1000);
    16                     } catch (InterruptedException e) {
    17                         e.printStackTrace();
    18                     }
    19                 }
    20             }
    21         }.start();
    22     }

     

    GitHub:https://github.com/godfunc
    博客园:http://www.cnblogs.com/godfunc
    Copyright ©2019 Godfunc
  • 相关阅读:
    Linux下设置 Tomcat JDK MySQL运用平台
    引见在Linux把持细碎下装置Tomcat的要领
    在linux下的freetds装置体式款式
    介绍两款超级小的linux,可以安排在u盘里玩
    在Debian环境下架设PPPoE效劳器2
    GRUB2 指导按次的开展目标
    Linux下设置配备布置服从完美的Web效力器
    Ubuntu Linux体系创设FTP办事器装备步调
    高效运用Linux的七个好习气2
    Ubuntu Linux 8.04零碎JAVA环境设置装备陈设体式格式
  • 原文地址:https://www.cnblogs.com/Godfunc/p/6024941.html
Copyright © 2011-2022 走看看