Android计数器>;=值不正确

Android计数器>;=值不正确,android,listener,counter,Android,Listener,Counter,我有几个加减按钮。我想显示弹出,如果计数器下降到0或以下,表示游戏结束。我有winGame();每个按钮下的功能设置单击Listener以检查计数器总数。 **我遇到的问题是,无论计数器的值是多少,它总是显示文本框说游戏结束。每次点击一个按钮进行加减操作时,总自动弹出文本框。同样值得注意的是,当应用程序启动时,计数器从20开始。 这是代码 void winGame() { if (counter1 <= 0 || counter <=0 );

我有几个加减按钮。我想显示弹出,如果计数器下降到0或以下,表示游戏结束。我有winGame();每个按钮下的功能设置单击Listener以检查计数器总数。 **我遇到的问题是,无论计数器的值是多少,它总是显示文本框说游戏结束。每次点击一个按钮进行加减操作时,总自动弹出文本框。同样值得注意的是,当应用程序启动时,计数器从20开始。 这是代码

            void winGame() {
    if (counter1 <= 0 || counter <=0 );
    String text = "Game Over";

    // Build a dialog box and with the result string and a single button
    AlertDialog.Builder game = new AlertDialog.Builder(this);
    game.setMessage(text).setCancelable(false)
            .setPositiveButton("OK", new 
            DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id)   
            {
                    // do things when the user clicks ok.
                }
            });
    AlertDialog alert = game.create();

    // Show the dialog box.
    alert.show();
}
void winGame(){
如果(counter1一个微妙的小错误

if (counter1 <= 0 || counter <=0 );
if(counter1一个微妙的小错误

if (counter1 <= 0 || counter <=0 );

if(counter1和
字符串文本
需要在
if
语句之外声明-但至少这会导致编译时错误。void winGame(){if(当然是counter1,
if(计数器1是的,这正是我想要的。附带问题,请不要回答,因为你已经帮了我很大的忙,如果我想在游戏上方弹出的OK按钮旁边显示一个重置按钮?我知道如何显示按钮,但不重置计数器的值。我应该尝试键入该代码在询问之前。非常感谢您的帮助!并且需要在
if
语句之外声明
String text
,但至少这会导致编译时错误。void winGame(){if(当然是计数器1,
if(计数器1是的,这正是我想要的。附带问题,请不要回答,因为你已经帮了我很大的忙,如果我想在游戏上方弹出的OK按钮旁边显示一个重置按钮?我知道如何显示按钮,但不重置计数器的值。我应该尝试键入该代码在询问之前。非常感谢您的帮助!
void winGame() {
    if (counter1 <= 0 || counter <=0 )
    {
        String text = "Game Over";

        // Build a dialog box and with the result string and a single button
        AlertDialog.Builder game = new AlertDialog.Builder(this);
        game.setMessage(text).setCancelable(false)
            .setPositiveButton("OK", new 
        DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id)   
            {
                // do things when the user clicks ok.
            }
        });
        AlertDialog alert = game.create();

        // Show the dialog box.
        alert.show();
    }
}