gpt4 book ai didi

android - onPostExecute 中的 AlertDialog 未显示

转载 作者:太空宇宙 更新时间:2023-11-03 13:33:47 25 4
gpt4 key购买 nike

我正在尝试在 AsyncTask 的 onPostExecute 方法上显示一个对话框

@Override
protected void onPostExecute(HttpResponse response) {
if (response == null) {
Log.d(TAG, "onPostExecute, response == null");
AlertDialog.Builder builder = new AlertDialog.Builder(ConfirmPhoneNoCode.this);
builder.setMessage("Are you sure you want to exit?").setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
ConfirmPhoneNoCode.this.finish();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
} else {
int responseCode = response.getStatusLine().getStatusCode();
String message = response.getStatusLine().getReasonPhrase();
Log.d(TAG, "Response Code: " + String.valueOf(responseCode));
Log.d(TAG, "Message: " + message);
}
}

我正在收到日志消息

03-31 23:02:42.912: D/ConfirmPhoneCode(21966): onPostExecute, response == null

这意味着

if(response == null) is executed but AlertDialog box don't show-up.

如果有人能帮助我,我将不胜感激。

提前致谢。

最佳答案

alert.show(); 我认为你必须添加它...

AlertDialog alert = builder.create();
alert.show();

关于android - onPostExecute 中的 AlertDialog 未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9958166/

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