gpt4 book ai didi

java - 进度条对话框关闭后如何显示警报对话框?

转载 作者:行者123 更新时间:2023-11-30 03:08:00 26 4
gpt4 key购买 nike

我想在进程栏对话框关闭后显示警报对话框(单击 ListView 以显示进程栏):这是我的代码显示过程栏对话框:

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();




}

请发布示例代码。非常感谢!!!

最佳答案

您需要在方法 setOnDismissListener(DialogInterface.OnDismissListener listener):AlertDialog 上实现接口(interface) DialogInterface.OnDismissListener。 它将帮助您完成所需的工作。下面的代码将帮助您完成所需的工作。

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();
}

我希望代码能帮助您解决问题。 :)

关于java - 进度条对话框关闭后如何显示警报对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21457851/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com