zoukankan      html  css  js  c++  java
  • Android——简易进度条与对话框

    在需要自行耗时操作的时候,且希望操作时不被中断,可以加个小进度

     1 public class MainActivity extends Activity {
     2 
     3 
     4     
     5     private ProgressDialog progressDialog;
     6 
     7     // ............
     8 
     9     /**
    10      * 显示进度对话框,还可以设置标题等等
    11      */
    12     private void showProgressDialog() {
    13         if (progressDialog == null) {
    14             progressDialog = new ProgressDialog(this);
    15             progressDialog.setMessage("正在加载...");
    16             progressDialog.setCanceledOnTouchOutside(false);
    17         }
    18         progressDialog.show();
    19     }
    20     
    21     /**
    22      * 关闭进度对话框
    23      */
    24     private void closeProgressDialog() {
    25         if (progressDialog != null) {
    26             progressDialog.dismiss();
    27         }
    28     }
    29     
    30 
    31 }

     需要提示用户可以增加一个对话框

     1         AlertDialog.Builder dialog = new AlertDialog.Builder(MainActivity.this);
     2         dialog.setTitle("this is dialog");
     3         dialog.setMessage("this is alert message");
     4         // 默认为true,back会取消dialog;false为屏蔽返回键!
     5         dialog.setCancelable(false);
     6         dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
     7             
     8             @Override
     9             public void onClick(DialogInterface dialog, int which) {
    10                 // 执行确认操作
    11                 
    12             }
    13         });
    14         dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
    15             
    16             @Override
    17             public void onClick(DialogInterface dialog, int which) {
    18                 // 执行取消的操作
    19                 
    20             }
    21         });
    22         dialog.show();
  • 相关阅读:
    解决vs code just-in-time报错的方法
    c++ 右值引用
    c++11 知识点
    ip路由名词介绍&琐碎知识
    第二次结对作业
    软工程第三次作业
    第二次作业
    软件工程第一次作业
    理解Object.defineProperty()
    concat()拷贝的局限性
  • 原文地址:https://www.cnblogs.com/erhai/p/4981251.html
Copyright © 2011-2022 走看看