我正在做我的android项目。我用YES和NO按钮创建了对话框。如果我单击是,则应显示一个新对话框,其中包含要选择的选项。我创建了带有选项的对话框。但是当我在我首先创建的对话框中单击“是”时,无法显示它。我该怎么做?请帮忙。 感谢。
这是我创建的对话框的代码。当我在此对话框中单击“是”按钮时,我应该显示另一个对话框
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Low Memory\nYou want to send the file to server?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
答案 0 :(得分:4)
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Low Memory\nYou want to send the file to server?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
AlertDialog.Builder builder2 = new AlertDialog.Builder(CLASSNAME.this);
builder2.setTitle("hi!");
//etc
builder2.show();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
希望这会有所帮助。 ;)
答案 1 :(得分:0)
试试这段代码:
AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
builder1.setMessage("Are you absolutely positively sure?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
finish();
}
});
final AlertDialog alert1 = builder1.create();
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Low Memory\nYou want to send the file to server?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
alert1.show();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
finish();
}
});
AlertDialog alert = builder.create();
alert.show();
答案 2 :(得分:0)
看看这个
AlertDialog alertDialog1,alertDialog2;
public void showAlertDialog1(String title,String message,final Context context)
{
alertDialog1 = new AlertDialog.Builder(context).create();
alertDialog1.setTitle(title);
alertDialog1.setMessage(message);
alertDialog1.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
errorAlertDialog2("second AlertDialog","second AlertDialog",context)
}
});
alertDialog1.show();
}
public void showAlertDialog2(String title,String message,Context context)
{
alertDialog2 = new AlertDialog.Builder(context).create();
alertDialog2.setTitle(title);
alertDialog2.setMessage(message);
alertDialog2.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
alertDialog2.dismiss();
}
});
alertDialog2.show();
}