[Android] ProgressDialog与线程整合使用,显示BusyMark

 

package com.example;

import android.app.Activity;

import android.app.ProgressDialog;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

public class EX0318 extends Activity

{

  private Button mButton1;

  private TextView mTextView1;

  public ProgressDialog myDialog = null;

  /** Called when the activity is first created. */

  @Override

  public void onCreate(Bundle savedInstanceState)

  {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

   

    mButton1 =(Button) findViewById(R.id.myButton1);

    mTextView1 = (TextView) findViewById(R.id.myTextView1);

    mButton1.setOnClickListener(myShowProgressBar);

  }

  Button.OnClickListener myShowProgressBar =

    new Button.OnClickListener()

  {

    public void onClick(View arg0)

    {

      final CharSequence strDialogTitle =

        getString(R.string.str_dialog_title);

      final CharSequence strDialogBody =

        getString(R.string.str_dialog_body);

      // 显示Progress对话框

      myDialog = ProgressDialog.show

      ( EX0318.this,

          strDialogTitle,

          strDialogBody,

          true );

      mTextView1.setText(strDialogBody);

      new Thread()

      {

        public void run()

        {

          try

          {

            /* 在这里写上要背景执行的程序片段 */

            /* 为了明显看见效果,以暂停3秒作为示范 */

            sleep(3000);

          }

          catch (Exception e)

          {

            e.printStackTrace();

          }

          finally

          {

            // 卸除所建立的myDialog对象。

            myDialog.dismiss();

          }

        }

       }.start(); /* 开始执行线程 */

     }

    /*End: public void onClick(View arg0)*/

  };

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值