android- AlertDialog显示两次

时间:2013-10-24 06:40:07

标签: java android

我有一个alertDialog,我正在创建另一个alertDialog。问题是第一个alertDialog弹出两次。因此,第二个alertDialog也创建了两次。这是我的代码 -

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();
        }
    }

1 个答案:

答案 0 :(得分:0)

问题不在于AlertDialog,而在于onOptionsItemSelectedHere就是答案。