自己写了一个小程序
自定一个一个GameView extends View
{
}
这个类里面有个函数 isOver()就是判断游戏是否结束?
GameView extends View
{
if(isOver())
{
AlertDialog.builder(……).show();
}
}自己定义一个Activity
Game extends Acivity
{
……
setContentView(new GameView());
}如果游戏结束 对话框就会显示出来,这个对话框中有一个确定按钮,
现在的问题是:如何能够做到我点击确定按钮能够把Game这个activity给关掉 也就是finish掉!!
自定一个一个GameView extends View
{
}
这个类里面有个函数 isOver()就是判断游戏是否结束?
GameView extends View
{
if(isOver())
{
AlertDialog.builder(……).show();
}
}自己定义一个Activity
Game extends Acivity
{
……
setContentView(new GameView());
}如果游戏结束 对话框就会显示出来,这个对话框中有一个确定按钮,
现在的问题是:如何能够做到我点击确定按钮能够把Game这个activity给关掉 也就是finish掉!!
if(isOver())
{
new AlertDialog.Builder(this)
.setTitle("GAMEOVER")
.setMessage("Quit?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Game.finish();//结束游戏
super.finish();
}
})
.show();
}
看这样行不行?
貌似不可以
Context context;
public GameView(Context context){
this.context = context;
} public void closeGame(){
context.finish();
}
}试试看行不行
Game.finish();//结束游戏
super.finish();肯定不行!
public GameView extends View{
Context context;
public GameView(Game activity){
this.context = activity;
} public void closeGame(){
context.finish();
}
}
Game activity
public GameView(Game activity){
this.context = activity;
} public void closeGame(){
this.activity.finish();
}
}