【问题标题】:How to open Dialog Box in android?如何在android中打开对话框?
【发布时间】:2020-04-08 13:56:14
【问题描述】:

我正在使用 android 的 Intent 方法从图库中选择图像。

现在选择图像后, 我想在一个对话框中询问用户,他必须选择是或否。

我该怎么做?

代码:

            Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
            if (intent.resolveActivity(getPackageManager()) != null)
            {
                startActivityForResult(intent, 1);
            }

我想在此处打开对话框

onActivityResult

,选择图片后。

【问题讨论】:

  • 到目前为止你尝试了什么?
  • 我已经更新了我的问题@IntelliJAmiya

标签: android android-studio android-intent android-alertdialog


【解决方案1】:

对话框的制作方法

new AlertDialog.Builder(context)
    .setTitle("Delete entry")
    .setMessage("Are you sure you want to delete this entry?")

    // Specifying a listener allows you to take an action before dismissing the dialog.
    // The dialog is automatically dismissed when a dialog button is clicked.
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // Continue with delete operation
        }
     })

    // A null listener allows the button to dismiss the dialog and take no further action.
    .setNegativeButton(android.R.string.no, null)
    .setIcon(android.R.drawable.ic_dialog_alert)
    .show();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-07-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多