我试图在另一个 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();
最佳答案
问题可能是您为 AlertDialog
使用的上下文。尝试在两者中使用 MyActivityName.this
,将 MyActivityName 替换为您的 Activity
的名称。
所以,构建第一个 AlertDialog
应该是这样的
AlertDialog.Builder alert = new AlertDialog.Builder(MyActivityName.this);
然后
AlertDialog.Builder alert2 = new AlertDialog.Builder(MyActivityName.this);
第二个。
关于android - AlertDialog.Builder 打开另一个AlertDialog.Builder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9343314/