1

I know how to disable the back button, but not during a popup.

syncb=(Button) findViewById(R.id.SyncB);
syncb.setOnClickListener(new View.OnClickListener() 
    {
        public void onClick(View v) 
        {
            final Dialog dialog = new Dialog(Scouting.this);
            dialog.setContentView(R.layout.popup);
            dialog.setTitle("Popups ftw");
            dialog.setCancelable(true);
            //I think I'd put the code here...
            Button button = (Button) dialog.findViewById(R.id.closePopup);
            button.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    dialog.dismiss();
                }    
            });
            dialog.show();
        }
    });

I've tried everything from

@Override public void dialog.onBackPressed() { }

to

@Override dialog.onBackPressed({});

and I can't find anything that works.

Edit: Usually, it's

@Override public void onBackPressed(){}

and it's usually in the main class(not 'nested') but since I'm dug in a little...I'm not figuring it out(trying to, but not succeeding).

bluebl1
  • 176
  • 1
  • 4
  • 13
  • possible duplicate of [How to Prevent an Alert Dialog Getting Closed by Back Button](http://stackoverflow.com/questions/7113591/how-to-prevent-an-alert-dialog-getting-closed-by-back-button) – Ram kiran Pachigolla Nov 07 '12 at 05:40

1 Answers1

7

Did you try

dialog.setCancelable(false);

It works in my case.

You are setting it to true

dialog.setCancelable(true);

Just change that

Rob
  • 415,655
  • 72
  • 787
  • 1,044
MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
  • You know, I'm not that bad of a programmer, but sometimes I can make really stupid mistakes. Lol thanks! I will check your answer in 4 minutes(stackoverflow isn't letting me now) – bluebl1 Nov 07 '12 at 05:41
  • Well since we're talking about "cancelable", what's the difference between "canceling" a popup and "dismissing" a popup? – bluebl1 Nov 07 '12 at 05:42
  • Nevermind, http://stackoverflow.com/questions/3125647/what-is-the-difference-between-a-dialog-being-dismissed-or-canceled-in-android – bluebl1 Nov 07 '12 at 05:45
  • Cancel a dialog: You don't want to click on Ok or Cancel buttons, or Yes/No buttons of dialog. Just go back to your application. Dismiss a dialog: You will click on Yes/No, action will beperformed according to your click and then dialog will be dismissed – MysticMagicϡ Nov 07 '12 at 05:46
  • Someone attempted to edit this answer with this alternative recommendation: "Or just override following method `@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { Log.d("back", "back button pressed"); } return true; //to prevent this event from being propagated further. }`" – Rob Nov 07 '12 at 05:52
  • Yeah...and why can you edit other people's posts!? That's just asking for trouble. – bluebl1 Nov 07 '12 at 06:08