zoukankan      html  css  js  c++  java
  • 【安卓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

  • 相关阅读:
    BFS 简单思想以及代码
    01、Hibernate安装配置
    WireShark——ARP 协议包分析
    eNSP之VLAN设计实验
    eNSP 交换机 路由器 PC 互连设计/实现
    Windows常用的网络命令
    01、Git安装教程(windows)
    Java IO编程——文件拷贝
    Java 多线程编程——多线程
    Java IO编程——转换流
  • 原文地址:https://www.cnblogs.com/leelee/p/6907054.html
Copyright © 2011-2022 走看看