当用户想退出时,会弹出一个对话框,确定后,游戏将退出。我的代码没有调用另一个类。
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();
}
}