[英]Android alertdialog Box - Exiting from App
I'm trying to get my app to use the alertdialog box to either play another game (by clicking 'yes' or exiting the app (by clicking 'no'). 我正在尝试让我的应用使用alertdialog框来玩另一个游戏(通过单击“是”或退出该应用(通过单击“否”))。
I got it to reset the app fine but when trying to add the exit function ('no'), the .setTitle method is suddenly saying 'Cannot resolve method 'setTitle(java.lang.String)' 我将其重置为可以正常使用的应用程序,但是当尝试添加退出功能(“否”)时,.setTitle方法突然说“无法解析方法'setTitle(java.lang.String)”
It was fine before I added the '.setNegativeButton'. 在添加“ .setNegativeButton”之前还不错。
Can anyone see what I've done wrong? 谁能看到我做错了什么?
Thanks 谢谢
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(Task1Activity.this);
alert.setMessage("You have guessed incorrectly three times. " +
"The answer was " + ranNum + ". " + "Would you like to play again?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//dialog.dismiss();
Intent i = new Intent(Task1Activity.this, Task1Activity.class);
startActivity(i);
}
});
alert
.setCancelable(false)
.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
};
}
.setTitle("Unlucky!")
.create());
我认为.setTitle(...)之前有一个缺少的括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.