情况是这样的:
首先,使用ProgressDialog.STYLE_SPINNER 圆形进度显示,均不会出错。
使用STYLE_HORIZONTAL 则使用show函数创建的对象会出错。源码
package com.progressDialog;import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;public class ProgressDialogTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
final ProgressDialog progressDialog = ProgressDialog.show(ProgressDialogTest.this, "ProgressDialog_Run",
"30秒后消失",true);
//final ProgressDialog progressDialog = new ProgressDialog(ProgressDialogTest.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setIcon(R.drawable.icon);
progressDialog.setMax(100);
progressDialog.setProgress(0);
progressDialog.setSecondaryProgress(50);
progressDialog.setIndeterminate(false);
progressDialog.show();
progressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
AlertDialog.Builder dialogBuilder = new Builder(ProgressDialogTest.this);
dialogBuilder.setTitle("警告").setMessage("你确定要退出吗?").setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
progressDialog.dismiss();
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
return true;
}
});
new Thread(){ @Override
public void run() {
int proNum = 0;
try {
while(proNum <= 100){
sleep(100);
proNum++;
progressDialog.setProgress(proNum);
}
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
progressDialog.dismiss();}
super.run();
}
}.start();
}
});
}
}
final ProgressDialog progressDialog = ProgressDialog.show(ProgressDialogTest.this, "ProgressDialog_Run",
"30秒后消失",true); 这句只能在圆形进度条中使用,在条形中使用则报错? 何解?
//final ProgressDialog progressDialog = new ProgressDialog(ProgressDialogTest.this); 条形进度条正常!
在Android 1.5中测试的不晓得其他其他版本如何。
首先,使用ProgressDialog.STYLE_SPINNER 圆形进度显示,均不会出错。
使用STYLE_HORIZONTAL 则使用show函数创建的对象会出错。源码
package com.progressDialog;import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;public class ProgressDialogTest extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
final ProgressDialog progressDialog = ProgressDialog.show(ProgressDialogTest.this, "ProgressDialog_Run",
"30秒后消失",true);
//final ProgressDialog progressDialog = new ProgressDialog(ProgressDialogTest.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setIcon(R.drawable.icon);
progressDialog.setMax(100);
progressDialog.setProgress(0);
progressDialog.setSecondaryProgress(50);
progressDialog.setIndeterminate(false);
progressDialog.show();
progressDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
AlertDialog.Builder dialogBuilder = new Builder(ProgressDialogTest.this);
dialogBuilder.setTitle("警告").setMessage("你确定要退出吗?").setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
progressDialog.dismiss();
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).show();
return true;
}
});
new Thread(){ @Override
public void run() {
int proNum = 0;
try {
while(proNum <= 100){
sleep(100);
proNum++;
progressDialog.setProgress(proNum);
}
} catch (InterruptedException e) {
e.printStackTrace();
}finally{
progressDialog.dismiss();}
super.run();
}
}.start();
}
});
}
}
final ProgressDialog progressDialog = ProgressDialog.show(ProgressDialogTest.this, "ProgressDialog_Run",
"30秒后消失",true); 这句只能在圆形进度条中使用,在条形中使用则报错? 何解?
//final ProgressDialog progressDialog = new ProgressDialog(ProgressDialogTest.this); 条形进度条正常!
在Android 1.5中测试的不晓得其他其他版本如何。
解决方案 »
- 怎么获取android项目assets目录里的文件写入流OutputStream
- 求助大牛!如何使service不被kill或者被kill后马上重启
- 请问手机锁屏界面的时间显示在哪里?在线等,帮顶给分.
- 关于int数据转换String数据的问题
- ANDROID平台用什么开发语言比较合适?欢迎加入讨论
- android多点触摸实例代码的一点疑问
- 如何在动态创建的图片(Imageview)得到Imageview的R
- Android的Socket编程尝试失败了,求帮助
- 怎样判断当前Activity里面装的Fragment是哪个
- 携程酒店首页瀑布流如何实现的
- Android 画图时 如何控制透明区域不画图?
- overlay和surfaceflinger的 w_stride 和 w怎么理解阿?
和static 有没有关系呢?