gpt4 book ai didi

android - 自定义警报对话框未定义的方法

转载 作者:行者123 更新时间:2023-11-29 18:09:14 26 4
gpt4 key购买 nike

我是 android 的新手,我正在尝试让这个自定义对话框工作,我在 showDialog & removeDialog 上收到一个错误,上面写着 The method removeDialog (int) 未定义 new DialogInterface.OnClickListener 类型。

onReceive 方法:

showDialog(DIALOG_TEXT_ENTRY);

代码:

    private static final int MY_PASSWORD_DIALOG_ID = 0;

MediaPlayer mp;
Context context;

protected Dialog onCreateDialog(int id, Context context) {

Dialog dialog = null;
switch(id) {
case MY_PASSWORD_DIALOG_ID:
LayoutInflater factory = LayoutInflater.from(context);

final View textEntryView = factory.inflate(R.layout.password_dialog, null);

final EditText password1 = (EditText) textEntryView.findViewById(R.id.inputPassword);

AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Enter Password");
builder.setView(textEntryView);

builder.setPositiveButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
removeDialog(MY_PASSWORD_DIALOG_ID);
}
});

AlertDialog passwordDialog = builder.create();
return passwordDialog;
}
return null;
}

最佳答案

使用

dialog.dismiss();

代替

removeDialog(MY_PASSWORD_DIALOG_ID);

您不能在 BroadcastReceiver 中显示对话框。

但是,如果您想显示弹出屏幕,请创建一个带有对话框主题的 Activity 。

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

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