gpt4 book ai didi

android - alertdialog android 中的 AlertDialog

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:39:36 26 4
gpt4 key购买 nike

我正在尝试在警报对话框中添加一个警报对话框。但是看不到第二个警报对话框。请帮助我这是我显示的代码

AlertDialog alertDialog = new AlertDialog.Builder(myclass.this).create();
alertDialog.setTitle("First alert");
alertDialog.setMessage("first alert press");
alertDialog.setButton("ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
dialog.cancel();

AlertDialog alertDialog1 = new AlertDialog.Builder(myclass.this).create();
alertDialog1.setTitle("second alert dialog");
alertDialog1.setMessage("second alert dialog details");
alertDialog1.setButton("Scan Another", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}}); }

最佳答案

这将是一个迟到的答案,但您可以像这样在 onClickListener 中创建一个 AlertDialog:

public void onClick(DialogInterface dialog, int which) {
if (options[which] == "Manage") {
//Do smtg
} else {
dialog.dismiss();
final AlertDialog alert;

AlertDialog.Builder dialog2 = new AlertDialog.Builder(CategoryPage.this);
alert = dialog2.create();
alert.setTitle("Delete " + title + "?");
alert.setMessage("Are you sure you want to delete this category?");

alert.setButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(CategoryPage.this, "YESS", Toast.LENGTH_LONG).show();
}
});

alert.setButton2("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
alert.dismiss();
}
});

alert.show();
}
}

关于android - alertdialog android 中的 AlertDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7579963/

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