gpt4 book ai didi

android - 自定义警报对话框错误

转载 作者:行者123 更新时间:2023-11-29 18:13:17 25 4
gpt4 key购买 nike

大家好,提前致谢...

我试图在我的 Activity 中显示一个警告对话框,但我遇到了一些错误....

我遵循了 http://developer.android.com/guide/topics/ui/dialogs.html#ShowingADialog 中的代码该链接的最后一部分....

enter image description here

下面是我的同款

enter image description here

如图所示,我写了代码

enter image description here

我的代码如下,点击按钮时调用

AlertDialog.Builder builder;
AlertDialog alertDialog;
Context mContext;
mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.search_dialog,(ViewGroup)findViewById(R.id.search_root));
builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();
alertDialog.show();

唯一的区别是

public class CatalogueActivity extends FragmentActivity{

它显示如下错误

enter image description here

我希望你能理解我的问题......

最佳答案

而不是使用 getApplicationContext(),您应该使用 this 关键字,它指的是 Activity 的上下文。

builder = new AlertDialog.Builder(this);

关于android - 自定义警报对话框错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9601174/

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