gpt4 book ai didi

android - 想要为Android上的错误弹出消息

转载 作者:行者123 更新时间:2023-12-03 08:57:44 25 4
gpt4 key购买 nike

这是我要添加 pop 消息的方法。如果结果集包含“404”,我想显示一条消息。我不能在这里使用Toast,因为这还没有写在任何Activity Context上。

protected void onPostExecute(String result) {
// To make a popup notification when it is a Not Found Location
if(result.contains("404")){
return;
}

super.onPostExecute(result);
if (baseFragment != null) {
if (isMainTask) {
baseFragment.onTaskFinished(result);
} else {
baseFragment.onSubTaskFinished(result);
}
}
}

最佳答案

要创建任何类型的ErrorDialog/Dialog或PopupWindow,您需要 Activity Context。 PFB返回警报对话框的示例代码:

return new AlertDialog.Builder(baseFragment.getActivity().getApplicationContext())
.setTitle("TITLE OF YOUR ALERT DIALOG")
.setMessage(“MESSAGE YOU WANT TO SHOW”)
.setCancelable(false)
.setPositiveButton("BUTTON NAME",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
removeDialog(The id of the managed dialog);


//TASK YOU WANT TO PERFORM
finish();
}
})
.setNegativeButton("BUTTON NAME",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
removeDialog(The id of the managed dialog);
finish();
}
}).create();

关于android - 想要为Android上的错误弹出消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18714098/

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