gpt4 book ai didi

java Android - 两个对话框,防止第一个对话框在第二个对话框退出后关闭

转载 作者:行者123 更新时间:2023-11-30 01:15:09 25 4
gpt4 key购买 nike

最初在我的应用程序中,我创建了一个具有三个按钮的 AlertDialog,其中中间的按钮打开另一个 AlertDialog。问题在于,当按下按钮后第二个 AlertDialog 关闭时,第一个也会随之关闭。我认为在我按下第二个 AlertDialog 上的按钮后,两个 AlertDialogs 都关闭了。

我想要的是第一个 AlertDialog 打开另一个有自己按钮的 AlertDialog ,当第二个 AlertDialog 按下一个按钮时,它只会自行关闭并返回到第一个。有什么办法可以实现吗?

下面是用于打开AlertDialog 按钮的代码:

final ImageButton fabgroup = (ImageButton) findViewById(R.id.groupButton);

下面是一个按钮的代码,该按钮打开一个 AlertDialog,该按钮包含另一个按钮,该按钮使用自身的中间按钮(创建按钮)打开另一个 AlertDialog,但同时关闭它们当按下第二个按钮时(是或否按钮,这不是我想要的,因为我只希望第二个按钮自行关闭并返回到第一个 AlertDialog,是的这在理论上听起来很困惑,所以如果需要我可以尝试澄清):

    fabgroup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(CreateNote.this);
helpBuilder.setTitle("Select a group");
helpBuilder.setMessage("Add to group?");

final TextView input = new TextView(mainactiv.this);
input.setSingleLine();
input.setText("");
helpBuilder.setView(input);

helpBuilder.setNegativeButton("Yes",
new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
// Do nothing but close the dialog
Toast.makeText(CreateNote.this, "Page has been added to group", Toast.LENGTH_SHORT).show();
}
});


helpBuilder.setNeutralButton("Create", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {


//open another alertbox
AlertDialog.Builder helpBuilder2 = new AlertDialog.Builder(CreateNote.this);
helpBuilder2.setTitle("Assign a new group");
helpBuilder2.setMessage("Create group?");

final EditText input = new EditText(CreateNote.this);
input.setSingleLine();
input.setText("");
helpBuilder2.setView(input);

helpBuilder2.setNegativeButton("Yes",
new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
// Create Group
Toast.makeText(CreateNote.this, "Group has been created", Toast.LENGTH_SHORT).show();
}
});

helpBuilder2.setPositiveButton("No", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
});

// Remember, create doesn't show the dialog
AlertDialog helpDialog2 = helpBuilder2.create();
helpDialog2.show();

}
});

helpBuilder.setPositiveButton("No", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
}
});

// Remember, create doesn't show the dialog
AlertDialog helpDialog = helpBuilder.create();
helpDialog.show();
}
});

帮助将不胜感激。

最佳答案

我最终设法通过创建两个单独的函数来生成每个对话框来解决这个问题,当一个对话框关闭时,它会调用该函数来创建另一个对话框,有点像回收(或者可能更接近于循环函数)。虽然,我不完全确定这对性能有多大影响,但它似乎可以完成这项工作,而我正在测试的内容没有任何问题。如果有人想插话这怎么可能成为一个问题,那么我很乐意听取其他人对以这种方式使用警告对话框的负面影响的看法。

关于java Android - 两个对话框,防止第一个对话框在第二个对话框退出后关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37956677/

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