gpt4 book ai didi

java - 带有游戏分数的自定义对话框 android

转载 作者:太空宇宙 更新时间:2023-11-04 15:05:05 24 4
gpt4 key购买 nike

我遇到了一个大问题。当我有了 AlertBox 时,一切都很好,但我会将其更改为具有漂亮图形的自定义对话框。通过 AlertBox,它可以显示当前分数和最高分。

当我将其更改为自定义对话框时,它什么也不显示。

CustomDialogClass.java

public class CustomDialogClass extends Dialog
{
public CustomDialogClass(Context context) {
super(context);
// TODO Auto-generated constructor stub


/** It will hide the title */
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_dialog);

}
}

GameActivity.java(带有自定义对话框的 fragment )

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
surfaceCreated = false;
stopDrawingThread();
}




public void customizeDialog() {
int highest = PrefUtil.getHighestScore(this);
String text = null;
if (currentPoint > highest) {
highest = currentPoint;
PrefUtil.setHighestScore(this, currentPoint);
} else {
}

text = "Current Points: " + currentPoint + "\nThe Best Score: " + highest;
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Game Over");
builder.setMessage(text);
builder.setPositiveButton("Try Again", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {
playSwooshing();
restart();
}
});
builder.setNegativeButton("Exit Game", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {


Intent intent = new Intent(GameActivity.this,Bye.class);
startActivity(intent);
playSwooshing();
finish();
}

});
builder.setCancelable(false);
alertDialog = builder.show();
}

和另一个 fragment :

private void onGameOver() {
runOnUiThread(new Runnable() {

@Override
public void run() {
if (!isFinishing()) {
soundPool.play(soundIds[SOUND_DIE], 0.5f, 0.5f, 1, 0, 1);
CustomDialogClass customizeDialog = new CustomDialogClass(GameActivity.this);
customizeDialog.show(); }
}
});
}

哪里有问题?有人可以修复它吗?现在它只显示我的布局文件,没有任何数据。

谢谢!

最佳答案

它不会显示您的数据,因为您没有设置数据。在使用 Builder 创建对话框的中间代码 fragment 中,您没有使用自定义对话框,因此显然不再调用该代码。同样,在您创建自定义对话框的最后一个 fragment 中,您没有设置任何数据。

请参阅documentation :

If you want a custom layout in a dialog, create a layout and add it to an AlertDialog by calling setView() on your AlertDialog.Builder object.

By default, the custom layout fills the dialog window, but you can still use AlertDialog.Builder methods to add buttons and a title.

关于java - 带有游戏分数的自定义对话框 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22107687/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com