如何保持AlertDialog直到单击按钮

时间:2017-05-21 15:26:44

标签: android

我有这段代码:

AlertDialog.Builder builder = new AlertDialog.Builder(activity.this);
        builder.setMessage("Message")
                .setTitle("Title");
        builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
            }
        });

        AlertDialog dialog = builder.create();
        dialog.show();
        Intent intent = new Intent(this, Menu.class);
        startActivity(intent);
        finish();

但它显示第二个AlertDialog并切换到另一个活动。如何让它等待点击PositiveButton?

1 个答案:

答案 0 :(得分:0)

   AlertDialog.Builder builder = new AlertDialog.Builder(activity.this);
    builder.setMessage("Message")
            .setTitle("Title");
    builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {

    Intent intent = new Intent(this, Menu.class);
    startActivity(intent);
    finish();
        }
    });

    AlertDialog dialog = builder.create();
    dialog.show();