小编Seb*_*ian的帖子

AlertDialog 不会关闭,需要点按两次才能关闭

我已经尝试学习和使用 Android Studio 大约 3 周了。我刚刚遇到了一种情况,即 AlertDialogue 在点击肯定按钮时不会关闭。

private void showGPSDisabledAlertToUser() {
    AlertDialog.Builder builder;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        builder = new AlertDialog.Builder(this, android.R.style.Theme_Material_Dialog_Alert);
    } else {
        builder = new AlertDialog.Builder(this);
    }

    builder.setTitle("Turn On Location / GPS");
    builder.setCancelable(false);
    builder.setMessage("Application Needs To Determine Device's Physical Location.");
    builder.setPositiveButton("YES, TURN ON", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss(); // This ain't working
                    goToInternetSettings();
                }
            });
    builder.setNegativeButton("NO, CANCEL", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    closeApplication();
                } …
Run Code Online (Sandbox Code Playgroud)

java android android-alertdialog

5
推荐指数
2
解决办法
2380
查看次数

标签 统计

android ×1

android-alertdialog ×1

java ×1