gpt4 book ai didi

android - 如何在延迟 n 秒后动态显示进度对话框按钮

转载 作者:搜寻专家 更新时间:2023-11-01 08:02:20 25 4
gpt4 key购买 nike

如何在 ProgressDialog 显示的 n 秒(固定)延迟后显示 ProgressDialog 按钮?

更清楚地说,ProgressDialog 正常启动。如何在 n 秒后在其中显示一个按钮?

L.F.

编辑

使用 Segi 和 android_beginner 的答案(非常感谢)我发布了我的问题的解决方案:

        pDialog = new ProgressDialog(mContext);
pDialog.setTitle(Reso.getString(mContext, R.string.waiting));
pDialog.setMessage(Reso.getString(mContext, R.string.waiting));
pDialog.setIndeterminate(true);
pDialog.setCancelable(false);
pDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
Reso.getString(mContext, R.string.annulla),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Stuff
}
});
pDialog.show();
pDialog.getButton(DialogInterface.BUTTON_NEGATIVE).setVisibility(View.INVISIBLE);

int progressDialogCancelButtonDelay = 2500;

new CountDownTimer(progressDialogCancelButtonDelay, progressDialogCancelButtonDelay + 1) {

@Override public void onTick(long millisUntilFinished) { }

@Override public void onFinish() {
pDialog.getButton(ProgressDialog.BUTTON_NEGATIVE).setVisibility(View.VISIBLE);
}
}.start();

最佳答案

尝试类似下面的代码:

 ProgressDialog loadingDialog = ProgressDialog.show(activity.this, "", "Loading...",
true, false);

new Thread(new Runnable() {

@Override
public void run() {
try {

Thread.sleep(2500);
runOnUiThread(new Runnable() {
public void run() {



loadingDialog.dismiss();

loadingDialog.setButton(ProgressDialog.BUTTON_NEUTRAL,
"Close",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//button click stuff here
}
});

loadingDialog.show();
loadingDialog.getButton(ProgressDialog.BUTTON_NEUTRAL).setVisibility(View.INVISIBLE);

}
}
});
} catch (InterruptedException e) {
e.printStackTrace();
}

}
}).start();

关于android - 如何在延迟 n 秒后动态显示进度对话框按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19358572/

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