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
  • 相关阅读:
    SQLServer之数据库行锁
    SQLServer之锁定数据库表
    SQLServer之锁简介
    SQLServer之删除函数
    CMD命令行合并多个txt文件到一个txt文件
    CMD命令搜索有某文本文件的内容
    Oracle表结构修改触发视图无法正常使用问题
    java中final关键字
    SQL Server Url Decode函数
    使用SQL SERVER PIVOT实现行列转置
  • 原文地址:https://www.cnblogs.com/Godfunc/p/6024941.html
Copyright © 2011-2022 走看看