[Android] ProgressDialog与线程整合使用,显示BusyMark
2011-07-05 15:46
531 查看
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)*/
};
}
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)*/
};
}
相关文章推荐
- 【Android每日一讲】2012.11.01 程序加载中,请稍后 - ProgressDialog 与线程整合应用
- Android问题—Toast不显示的原因和在子线程中使用方法以及Looper类详细解析
- 在Android程序里显示等待滚动圈(使用ProgressDialog)| Show waiting rolling circle in android application (using ProgressDialog)
- android 自动更新APP版本,并使用ProgressDialog显示进度
- Android的线程使用来更新UI----Thread、Handler、Looper、TimerTask等
- Android中线程Thread的使用
- Android的线程使用来更新UI----Thread、Handler、Looper、TimerTask等
- android ijkplayer c层分析-渲染显示线程
- Android小例子:圆角按钮、CheckBox使用、退出确认框、Intent传值、Activity显示软件信息
- android线程使用注意问题?【安卓进化二】
- Android 使用Font Awesome 显示文字图标
- android 异步线程的使用
- Android的线程使用来更新UI----Thread、Handler、Looper、TimerTask等【转】
- 举例说明android中Bitmap、ListView以及ImageView的综合使用---显示图片并获取图片的宽和高
- Android使用ProgressBar、自定义Notification显示文件下载进度
- 关于android中线程的使用
- Android使用ImageView显示网络图片
- Android开发之子线程中Toast的显示
- android 解码出来的视频frame数据,是如何一步步的传递到显示端的(使用hwc composer online 合成)
- Android入门(12)——使用DataPicker以及TimePicker显示当前日期和时间