Thanks Marco.  Took out the super.onKeyDown and it does block... you're
right.
However, my complaint on the other thing - lack of setPositiveButton and
setNegativeButton - still stands :-)

If I do two calls to setButton, I only get the last button.  Were the above
two functions removed?

Thanks again.
Rob

On Fri, May 29, 2009 at 12:45 AM, Marco Nelissen <[email protected]>wrote:

> It's not a bug. I'm guessing you were expecting AlertDialog.show() to block
> until the user makes the choice, but that's not how it works.
> It's easy to make this work though: simply don't call super.onKeyDown()
> when the user pressed the back button. That will keep the system from ending
> your activity. Then just call finish() when you do want to end the activity.
>
>
>
> On Thu, May 28, 2009 at 9:36 PM, Rob Franz <[email protected]> wrote:
>
>>
>> Hi all,
>> I've got something simple where I want to raise an AlertDialog after
>> catching this keypress:
>>
>> @Override
>>            public boolean onKeyDown(int keyCode, KeyEvent event){
>>                super.onKeyDown(keyCode, event);
>>                switch (keyCode){
>>
>>                case KeyEvent.KEYCODE_BACK:
>>                        alertDialog= new
>> AlertDialog.Builder(this).create();
>>                        alertDialog.setTitle("Option");
>>                        alertDialog.setMessage("Perform?");
>>                        alertDialog.setButton("Yes", new
>> DialogInterface.OnClickListener
>> () {
>>                                public void onClick(DialogInterface dialog,
>> int whichButton) {
>>                                        setResult(RESULT_OK);
>>                                        finish();
>>                                }});
>>                        alertDialog.setButton("No", new
>> DialogInterface.OnClickListener
>> () {
>>                                public void onClick(DialogInterface dialog,
>> int whichButton) {
>>                                }});
>>                        alertDialog.show();
>>                        break;
>>
>>                default:
>>                        break;
>>
>>                }
>>                        return true;
>>            }
>>
>> The interesting thing here is that when you hit the back button, you
>> *do* see the AlertDialog for a split second, but then you're back at
>> the previous screen you were at.  Almost as if the system is hellbent
>> on sending the user back to the previous screen, regardless of what
>> the developer has constructed around this event.
>>
>> Anyone else see this behavior?  I'm using 1.5r2 here.  Any help would
>> be appreciated - I'm pretty sure I'm using this correctly and that
>> this is a bug.
>>
>> Thanks
>> Rob
>>
>>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to