• 【安卓5】高级控件——对话框操作事件


    事件处理接口

    接口名称

    描述

    DialogInterface.OnClickListener

    对话框单击事件处理接口

    DialogInterface.OnCancelListener

    对话框取消事件处理接口

    DialogInterface.OnDismissListener

    对话框隐藏事件处理接口

    DialogInterface.OnKeyListener

    对话框键盘事件处理接口

    DialogInterface.OnMultiChioceClickListener

    对话框多选事件处理接口

    DialogInterface.OnShowListener

    对话框显示事件处理接口

    对话框操作事件

    【删除】

     1 protected void onCreate(Bundle savedInstanceState) {
     2     super.onCreate (savedInstanceState);
     3     setContendView(R.layout.dialog);        //设置布局管理器
     4     Button bt = (Button) findViewById (R.id.button);
     5     bt.setOnClickListener (new OnClickListener () {
     6         public void onClick (View v) {
     7             Dialog dialog2=new AlertDialog.Builder (Dialog0.this)
     8                 .setTitle("删除")                        //设置标题
     9                 .setMessage("是否删除指定内容?")        //显示信息
    10                 .setPositiveButton("确定", new DialogInterface.OnClickListener() {
    11                     public void onClick(DialogInterface dialog, int which) {
    12                     }})
    13                 .setNeutralButton("取消", new DialogInterface.OnClickListener() {
    14                     public void onClick(DialogInterface dialog, int which) {
    15                     }})
    16                 .create();                //创建Dialog
    17             dialog2.show();            //显示对话框
    18             }
    19         });
    20 }
    View Code

    【退出】

    Dialog dialog2=new AlertDialog.Builder(Dialog0.this)
        .setTitle("退出")                        //设置标题
        .setMessage("是否退出程序?")        //显示信息
        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                    Dialog0.this.finish();    //退出程序
            }
        })
        .setNeutralButton("取消", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {}
        })
        .create();                            //创建Dialog
        dialog2.show();            //显示对话框
    View Code

    【进度处理】

     1 Button bt = (Button) findViewById(R.id.Dbt);
     2 bt.setOnClickListener(new OnClickListener() {
     3     public void onClick(View v) {
     4         final ProgressDialog pd=ProgressDialog.show(Dialog01.this,
     5              "搜索", "正在努力加载中。。。");
     6         new Thread(){                //线程对象
     7             public void run(){        //线程主体方法
     8                 try {
     9                     Thread.sleep(3000);        //运行3秒后关闭对话框
    10                 } catch (InterruptedException e) {
    11                     e.printStackTrace();
    12                 }finally{
    13                     pd.dismiss();    //关闭对话框
    14                 }
    15              }
    16          }.start();                //线程启动
    17         pd.show();
    18      }
    19 });
    View Code

  • 相关阅读:
    Python Module_openpyxl_styles 样式处理
    Python Module_openpyxl_styles 样式处理
    Microsoft Azure_Fabric
    Keepalived概述和安装(1)
    LVS集群TUN模式实例(5)
    LVS集群DR模式实例(4)
    LVS集群之NAT模式实例(3)
    LVS集群之工作原理和调度算法(2)
    HDFS基于路由的Federation方案
    HDFS基于路由的Federation方案
  • 原文地址:https://www.cnblogs.com/leelee/p/6907054.html
Copyright © 2020-2023  润新知