簡體   English   中英

Android alertdialog Box-從應用程序退出

[英]Android alertdialog Box - Exiting from App

我正在嘗試讓我的應用使用alertdialog框來玩另一個游戲(通過單擊“是”或退出該應用(通過單擊“否”))。

我將其重置為可以正常使用的應用程序,但是當嘗試添加退出功能(“否”)時,.setTitle方法突然說“無法解析方法'setTitle(java.lang.String)”

在添加“ .setNegativeButton”之前還不錯。

誰能看到我做錯了什么?

謝謝

@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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM