Java 当AlertDialog处于活动状态时,Android按钮设置按下的行为会发生变化

Java 当AlertDialog处于活动状态时,Android按钮设置按下的行为会发生变化,java,android,Java,Android,我目前有一个按钮,它在我正在创建的应用程序上被设置为按下(true)。当我按下后退按钮时,还会出现一个AlertDialog(警报)对话框。我注意到,当我按下后退按钮,AlertDialog(警报)对话框出现时,我设置为true的按钮会变为false。我不明白是什么原因导致了这种情况,因为我的代码中没有任何东西告诉按钮将setPressed更改为false。 如果有人愿意,我可以提供我的代码,但我相信是其他原因造成的。任何帮助都将不胜感激。:) “如果有人愿意,我可以提供我的代码,但我相信这是其

我目前有一个按钮,它在我正在创建的应用程序上被设置为按下(true)。当我按下后退按钮时,还会出现一个AlertDialog(警报)对话框。我注意到,当我按下后退按钮,AlertDialog(警报)对话框出现时,我设置为true的按钮会变为false。我不明白是什么原因导致了这种情况,因为我的代码中没有任何东西告诉按钮将setPressed更改为false。 如果有人愿意,我可以提供我的代码,但我相信是其他原因造成的。任何帮助都将不胜感激。:)


“如果有人愿意,我可以提供我的代码,但我相信这是其他原因造成的。”请始终提供代码的相关部分,否则其他人很难帮助你。即使您可能认为它与代码无关,但大多数情况下都与代码无关。这是我的退出方法,其中包括AlertDialog“我注意到,当我按下“后退”按钮时,AlertDialog对话框出现,我已将按下的按钮设置为“真”将更改为“假”。您在说什么按钮?按钮3。。。您将看到在.setNegativeButton下,我不得不再次将button3.setPressed设置为true,因为AlertDialog导致它变为false。@Dan_JAVA_SQL不知道您在做什么,但您可能需要寻找一些更好的设计建议。
public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        exitByBackKey();

        return true;
    }
    return super.onKeyDown(keyCode, event);
}

protected void exitByBackKey() {

    if(!instOn){
        if(toast != null) 
            toast.cancel();



        AlertDialog alertbox = new AlertDialog.Builder(this).setMessage("Do you want to exit?")
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface arg0, int arg1) {

                finish();
                System.exit(0);

            }
        })
        .setNegativeButton("No", new DialogInterface.OnClickListener() {

            // do something when the button is clicked
            public void onClick(DialogInterface arg0, int arg1) {
                 if(!stage1 || !stage2){
                     button3.setClickable(false);
                     button3.setPressed(true);
                 }
            }
        })
        .setNeutralButton("Restart", new DialogInterface.OnClickListener() {

            // do something when the button is clicked
            public void onClick(DialogInterface arg0, int arg1) {

                newGame();
            }
        })
        .show();
        //alertbox.setCancelable(false);

    }
    else{
        instOn = false;
        trans.transition.reverseTransition(800);
        popupWindow.dismiss();
        button1.setClickable(true);
        button2.setClickable(true);
        soundButton.setClickable(true); 
    }
}