有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java 安卓 AlertDialog显示两次

我有一个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) 个答案

  1. # 1 楼答案

    问题不在于AlertDialog,而在于onOptionsItemSelected中的Here就是答案