我正在开发一款android游戏。当应用程序启动时显示一个按钮(“开始”)来启动游戏。当用户输了,应用程序应该显示原始视图并将按钮文本更改为“重新启动”。当我启动应用程序时一切正常,但当用户失去时,我得到原始视图(按钮文本没有改变),甚至没有响应按钮。我有两个类:GameActivity和GameView: 在GameActivity我有这样的:按钮不更新其文本
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
init();
}
public void init() {
setContentView(R.layout.activity_catch_game);
fruitView = (CatchGameView) findViewById(R.id.l3InfoCatchGameView1);
fruitView.setActivity(this);
if (bStart == null) { //When we launch the app
bStart = (Button) findViewById(R.id.start);
bStart.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
buttonStartClickEventHandler();
}
});
} else{
bStart.setText("Restart");
}
}
在GameView我有这样的:
private void showScore() {
stopTimer();
AlertDialog.Builder popupBuilder = new AlertDialog.Builder(
this.getContext());
TextView message = new TextView(this.getContext());
message.setText("Score : " + score);
message.setGravity(Gravity.CENTER_HORIZONTAL);
popupBuilder.setView(message);
popupBuilder.setCancelable(true);
popupBuilder.setNeutralButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
invalidate();
activity.init();
}
});
popupBuilder.show();
}
当我调试我看到的是改变指令按钮上的文字是执行。感谢您的帮助
你是什么意思用户输了? – Libin
当比赛结束时。当用户输了我的比赛结束。 – Hunsu