Android AlertDialog中的AlertDialog
我试图在AlertDialog中创建AlertDialog,但是当我运行代码时,secound AlertDialog没有出现 这是我的代码,我想让它像如果用户在第一个AlertDialog中单击取消,第二个AlertDialog将出现,用户可以键入他的名字,分数和名字都将通过intern传递给ScoreActivityAndroid AlertDialog中的AlertDialog,android,Android,我试图在AlertDialog中创建AlertDialog,但是当我运行代码时,secound AlertDialog没有出现 这是我的代码,我想让它像如果用户在第一个AlertDialog中单击取消,第二个AlertDialog将出现,用户可以键入他的名字,分数和名字都将通过intern传递给ScoreActivity void generateAlertDialog(final long timeSpent) { // 1. Instantiate an AlertDialo
void generateAlertDialog(final long timeSpent) {
// 1. Instantiate an AlertDialog.Builder with its constructor
AlertDialog.Builder builder = new AlertDialog.Builder(
GameActivity.this);
// 2. Chain together various setter methods to set the dialog
// characteristics
builder.setMessage(
"The time stayed in the game is " + timeSpent + "s")
.setTitle("You Lose!!")
.setPositiveButton("Replay",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
// User clicked OK button
finish();
Intent intent = new Intent(getApplicationContext(), GameActivity.class);
startActivity(intent);
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
AlertDialog.Builder builder2 = new AlertDialog.Builder(
GameActivity.this);
builder2.setMessage(
"Please input you name")
.setTitle("Score");
final EditText input = new EditText(GameActivity.this);
input.setInputType(InputType.TYPE_CLASS_TEXT);
builder2.setView(input);
builder2.setPositiveButton("Show Score LIst",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
finish();
Intent intent = new Intent(getApplicationContext(), ScoreActivity.class);
m_Text = input.getText().toString();
intent.putExtra("name", m_Text);
intent.putExtra("result", timeSpent);
startActivity(intent);
}
});
builder2.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
finish();
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
});
// User cancelled the dialog
}
});
// 3. Get the AlertDialogfrom create()
AlertDialog dialog = builder.create();
// 4. Show dialog
dialog.show();
}
您从不调用
builder2.create()
或builder2.create()
返回的任何方法的show()
。您需要在注释“/”用户取消对话框的地方执行这两项操作。您尝试更改AlertDialog.Builder builder2=new AlertDialog.Builder(GameActivity.this)代码>至AlertDialog.Builder builder2=新建AlertDialog.Builder(此)代码>