我想在处理栏对话框dismis后显示警告对话框(在listview上显示以显示处理栏): 这是我的代码show processbar对话框:
ProgressDialog barProgressDialog;
Handler updateBarHandler;
public void launchBarDialog(View view)
{
barProgressDialog = new ProgressDialog(MainActivity.this);
barProgressDialog.setTitle("Processing,please wait ...");
barProgressDialog.setMessage("Cracking password in progress ...");
barProgressDialog.setProgressStyle(barProgressDialog.STYLE_HORIZONTAL);
barProgressDialog.setProgress(0);
barProgressDialog.setMax(10);
barProgressDialog.show();
new Thread(new Runnable() {
@Override
public void run() {
try {
// Here you should write your time consuming task...
while (barProgressDialog.getProgress() <= barProgressDialog.getMax()) {
Thread.sleep(1000);
updateBarHandler.post(new Runnable() {
public void run() {
barProgressDialog.incrementProgressBy(2);
}
});
if (barProgressDialog.getProgress() == barProgressDialog.getMax()) {
barProgressDialog.dismiss();
}
}
} catch (Exception e) {
}
}
}).start();
}
请发布示例代码。非常感谢!!!
答案 0 :(得分:1)
您需要在方法 setOnDismissListener(DialogInterface.OnDismissListener listener)上实现接口DialogInterface.OnDismissListener:AlertDialog。它将帮助您完成所需的操作。以下代码将帮助您完成所需的操作。
ProgressDialog barProgressDialog;
Handler updateBarHandler;
public void launchBarDialog(View view) {
updateBarHandler = new Handler();
barProgressDialog = new ProgressDialog(MainActivity.this);
barProgressDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
//Put your AlertDialog Here ....
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
alert.setMessage("This Alert Dialog will be show after the ProgressDialog dismissed");
alert.show();
}
});
barProgressDialog.setTitle("Processing,please wait ...");
barProgressDialog.setMessage("Cracking password in progress ...");
barProgressDialog.setProgressStyle(barProgressDialog.STYLE_HORIZONTAL);
barProgressDialog.setProgress(0);
barProgressDialog.setMax(10);
barProgressDialog.show();
new Thread(new Runnable() {
@Override
public void run() {
try {
// Here you should write your time consuming task...
while (barProgressDialog.getProgress() <= barProgressDialog
.getMax()) {
Thread.sleep(1000);
updateBarHandler.post(new Runnable() {
public void run() {
barProgressDialog.incrementProgressBy(2);
if (barProgressDialog.getProgress() == barProgressDialog
.getMax()) {
barProgressDialog.dismiss();
}
}
});
}
} catch (Exception e) {
Log.e("thiago", "error when trying to run the Thread==>"+e.getMessage());
}
}
}).start();
}
我希望代码可以帮助您解决问题。 :)
答案 1 :(得分:0)