0

当用户想退出时,会弹出一个对话框,确定后,游戏将退出。我的代码没有调用另一个类。

private void giveup(){
    Context mcontext=this;      
    final AlertDialog.Builder alert = new AlertDialog.Builder(
                  mcontext);

    alert.setTitle("Are you sure to give up?");
    alert.setNegativeButton("Cancel",
        new DialogInterface.OnClickListener() {
              @Override
              public void onClick(DialogInterface dialog,
                  int which) {
                  click.start();   
                  dialog.cancel();                                            

              } });
        alert.setPositiveButton("OK",
              new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog,
                           int which) {
                       click.start();                                           
                       dialog.cancel();
                       try{
                           Class<?> ourClass = Class.forName("com.ithinkDictionary.Gameover");
                           Intent ourIntent = new Intent(Playing.this, ourClass);
                           startActivity(ourIntent);
                       }catch(ClassNotFoundException e){
                            e.printStackTrace();
                  }
              } 
        });
        alert.show();   
    }
}           
4

1 回答 1

3

你应该只使用

Intent ourIntent = new Intent(Playing.this, Gameover.class);
                            startActivity(ourIntent);

假设 Playing 和 Gameover 都是活动。

于 2013-02-01T09:49:56.927 回答