zoukankan      html  css  js  c++  java
  • ProgressDialog

    package com.pingyijinren.helloworld.activity;
    
    import android.app.ProgressDialog;
    import android.content.DialogInterface;
    import android.os.Handler;
    import android.os.Message;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;
    
    import com.pingyijinren.helloworld.R;
    public class MainActivity extends AppCompatActivity implements View.OnClickListener {
        private Button button;
        private ProgressDialog progressDialog;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            button=(Button)findViewById(R.id.button);
            button.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            progressDialog=new ProgressDialog(this);
            progressDialog.setIcon(R.mipmap.ic_launcher);
            progressDialog.setTitle("标题");
            progressDialog.setMessage("内容");
            progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "详细信息", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Toast.makeText(MainActivity.this,"你点击了详细信息",Toast.LENGTH_SHORT).show();
                }
            });
            progressDialog.show();
    
            new Thread(){
                @Override
                public void run() {
                    super.run();
                    for(int i=0;i<=100;i++){
                        Message message=new Message();
                        Bundle bundle=new Bundle();
                        bundle.putInt("i",i);
                        message.setData(bundle);
                        handler.sendMessage(message);
    
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }.start();
        }
        private Handler handler=new Handler(){
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                Bundle bundle=msg.getData();
                int i=bundle.getInt("i");
                progressDialog.setProgress(i);
            }
        };
    }
  • 相关阅读:
    联合索引和多个单列索引选择
    CentOS6.5 一台服务器同时安装多个Mysql数据库
    一次CentOS的服务器被攻击教训
    java版本的memcache静态化
    mysql存储空间满的处理方式
    MariaDB 10.0 和 MariaDB 10.1 存储过程中 PREPARE FROM EXECUTE 区别
    CentOS6.x 优化脚本
    Mysql 使用 “LOAD DATA INFILE”需要注意的问题
    Mysql 日期类型比较 TIMESTAMPDIFF
    CentOS6.x 源码安装Nginx
  • 原文地址:https://www.cnblogs.com/zqxLonely/p/5553593.html
Copyright © 2011-2022 走看看