0

I currently have a button which is setPressed(true) on an app i'm creating. I also have an AlertDialog box appear when I press the back button. I noticed that when I press the back button and the AlertDialog box appears the button I have set pressed to true changes to false. I can't understand what is causing this as there is nothing in my code to tell the button to change setPressed to false. I can supply my code if anyone wishes but I believe something else causes this. Any help would be hugely appreciated. :)

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); 
    }
}
Ryan J
  • 8,275
  • 3
  • 25
  • 28
M0rty
  • 985
  • 3
  • 15
  • 35
  • *"I can supply my code if anyone wishes but I believe something else causes this."* Please always supply the revelant part of your code else it is really harde for other to help you. Even if you may think it is not related to the code, most of the time it is. – Jean-François Savard Apr 15 '15 at 00:53
  • 1
    Here is my exit method which includes the AlertDialog – M0rty Apr 15 '15 at 00:56
  • _"I noticed that when I press the back button and the AlertDialog box appears the button I have set pressed to true changes to false."_ what button are you talking about? – Ryan J Apr 15 '15 at 01:03
  • button3... you will see under the .setNegativeButton I have had to set button3.setPressed to true again as the AlertDialog causes it to become false. – M0rty Apr 15 '15 at 01:08
  • @Dan_JAVA_SQL don't know what you're doing, but you might take a look [here](http://stackoverflow.com/questions/5975168/android-button-setpressed-after-onclick) for some better design suggestions. – Ryan J Apr 15 '15 at 02:04

0 Answers0