AlertDialog.Builder 打开另一个 AlertDialog.Builder
我正在尝试在另一个 AlertDialog
中打开一个 AlertDialog
,但它不起作用,您知道为什么它不起作用吗?
String items[] = {"Details","Edit","Delete"}
AlertDialog.Builder alert = new AlertDialog.Builder(getAplicationContext());
alert.setTitle("Options");
alert.setItems(items, new OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch(item){
case 0:
AlertDialog.Builder alert2 = new AlertDialog.Builder(getAplicationContext());
alert2.setTitle("Details");
alert2.setMessage(getDetails());
alert2.setNeutralButton("Close", null);
alert2.show();
return;
case 1:
//not important for the question
return;
case 2:
//not important for the question
return;
}
}
});
alert.setNegativeButton("Cancel", null);
alert.show();
I'm trying to open a AlertDialog
in another AlertDialog
, but it's not working, any ideas why it's not working?
String items[] = {"Details","Edit","Delete"}
AlertDialog.Builder alert = new AlertDialog.Builder(getAplicationContext());
alert.setTitle("Options");
alert.setItems(items, new OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch(item){
case 0:
AlertDialog.Builder alert2 = new AlertDialog.Builder(getAplicationContext());
alert2.setTitle("Details");
alert2.setMessage(getDetails());
alert2.setNeutralButton("Close", null);
alert2.show();
return;
case 1:
//not important for the question
return;
case 2:
//not important for the question
return;
}
}
});
alert.setNegativeButton("Cancel", null);
alert.show();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题可能是您用于
AlertDialog
的上下文。尝试在两者中使用MyActivityName.this
,将 MyActivityName 替换为您的Activity
的名称。因此,构建第一个
AlertDialog
应该如下所示AlertDialog.Builderalert = new AlertDialog.Builder(MyActivityName.this);
然后
AlertDialog.Builderalert2 = new AlertDialog.Builder(MyActivityName.this);
用于第二个。
The problem is probably the context you are using for the
AlertDialog
's. Try usingMyActivityName.this
in both, replacing MyActivityName with whatever the name of yourActivity
is.So, building the first
AlertDialog
should look like thisAlertDialog.Builder alert = new AlertDialog.Builder(MyActivityName.this);
and then
AlertDialog.Builder alert2 = new AlertDialog.Builder(MyActivityName.this);
for the second one.