0

I have an alertDialog from which I am creating another alertDialog. The problem is that the first alertDialog pops up twice. So, the second alertDialog is also created twice. Here is my code-

public void navigationMenu() {
        AlertDialog.Builder builder = new AlertDialog.Builder(
                getSherlockActivity());
        String[] items = { "Current Location", RajputanaGrnd.NAME,
                NCCOffice.NAME, NewMech.NAME, ChemGrounds.NAME, Rampur.NAME,
                "Swatantrata Bhavan Ground", ElectDept.NAME, ABLT.NAME };
        builder.setTitle("From:");
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                dialog.dismiss();
                AlertDialog.Builder builder1 = new AlertDialog.Builder(
                        getSherlockActivity());
                String[] items = { RajputanaGrnd.NAME, NCCOffice.NAME,
                        NewMech.NAME, ChemGrounds.NAME, Rampur.NAME,
                        "Swatantrata Bhavan Ground", ElectDept.NAME, ABLT.NAME };
                builder1.setTitle("To:");
                builder1.setItems(items, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();

                    }
                });
                AlertDialog alert1 = builder1.create();
                alert1.show();

            }
        });
        AlertDialog alert = builder.create();
        if (!alert.isShowing()) {
            alert.show();
        }
    }
Naddy
  • 2,664
  • 6
  • 25
  • 38
  • What do you mean by showing two times ? – GrIsHu Oct 24 '13 at 06:46
  • You have created two alerts and i have checked that it shows only single time both alerts. – GrIsHu Oct 24 '13 at 06:47
  • 1
    Are you sure that navigationMenu() is called only once at a time? – Abx Oct 24 '13 at 06:47
  • @Abhilash You were indeed right. navigationMenu() is getting called twice. I have posted another question [here](http://stackoverflow.com/questions/19564870/android-onoptionsitemselected-method-called-twice) regarding this. – Naddy Oct 24 '13 at 12:03
  • @GrIsHu navigationMenu() is getting called twice. Please see [this](http://stackoverflow.com/questions/19564870/android-onoptionsitemselected-method-called-twice) question. – Naddy Oct 24 '13 at 12:04

1 Answers1

0

The problem is not with AlertDialog but the in the onOptionsItemSelected. Here is the answer.

Community
  • 1
  • 1
Naddy
  • 2,664
  • 6
  • 25
  • 38