1

Can someone help me or point me to some resource where there is an example to show a dialog box over the MapActivity. I can show it in a usual activity but I am having some difficulty with the same thing inside a Map.

My code is something like

  AlertDialog.Builder builder = new AlertDialog.Builder(getBaseContext());
                        switch (id) {           
                        case GAME_OVER:         
                                builder.setMessage(R.string.gameovertext);
                                builder.setCancelable(false);
                                builder.setPositiveButton(
                                                R.string.yes, new DialogInterface.OnClickListener() {
                                                        public void onClick(DialogInterface dialog, int id) {
                                                                finish();
                                                        }               
                                                });      
                                builder.setNegativeButton(R.string.no, 
                                                new DialogInterface.OnClickListener() {
                                        public void onClick(DialogInterface dialog, int id) {
                                                dialog.cancel(); 
                                        }
                                });       
                                return builder.create();
                        }
                        return null;
prakashkut
  • 540
  • 1
  • 7
  • 16
  • Please post your code here so that we can know what's going on – hungr Mar 14 '12 at 00:50
  • You want to show the dialog as in Google Maps when you click it shows small dialog box...? – Scorpion Mar 14 '12 at 03:25
  • If you want the same thing then here is the link for you...https://github.com/jgilfelt/android-mapviewballoons. Hope this will help you... – Scorpion Mar 14 '12 at 03:26
  • No. I wanted to show the default dialog box we have in android when the user presses something on the map. – prakashkut Mar 14 '12 at 03:31

1 Answers1

0

@prakashkut When i see you code you are returning

    builder.create();

this is return when in switch case GAME_OVER is match

in your method return

you should receive it in

AlertDialog alert=receive your builder.create(); Here after that you have to show it by below code

alert.show();

you can refer this example for Android AlertDialog Box to show in Activity.Here is Link for Example

Herry
  • 7,037
  • 7
  • 50
  • 80
  • When I do that, I get an exception ERROR/AndroidRuntime(3119): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application – prakashkut Mar 14 '12 at 15:13
  • @prakashkut i have question about ,why you return builder.create(); in your switch case ,i think you should try this in your switch case AlertDialog alert – Herry Mar 15 '12 at 04:50
  • @here i one reference which is similar to your Exception ,http://stackoverflow.com/questions/1561803/android-progressdialog-show-crashes-with-getapplicationcontext – Herry Mar 15 '12 at 05:04