当我点击附件按钮时,它只显示警告对话框的标题。那么如何在警告对话框中显示选项

when i click on attachment button , it show me only the the title of alert dialog. So how to show the option in alert dialog

这是一个聊天应用程序,我想在用户点击附件按钮时显示选项,select一个选项,比如他想向其他用户发送图片或视频或文件文档。like this screenshot

但是我失败了,当我点击附件按钮时,它只显示警告对话框的标题。 like this screenshot

这是我的附件按钮代码,有一些东西我错过了或者....

        attachment.setOnClickListener {
        val option: Charsequence = Charsequence("Images" , "Videos" , "File Documents")
        val itemList = arrayOf("Images","Videos","File Documents")
        val builder = AlertDialog.Builder(this@ChatLogActivity)
        val title = builder.setTitle("Select The File")
        builder.setItems( itemList.toString() ,
            onClickListener = DialogInterface.OnClickListener { dialogInterface , i ->
                if (i == 0){
                    checker = "Images"
                    val intent = Intent(Intent.ACTION_GET_CONTENT)
                    intent.type = "image/*"
                    startActivityForResult(Intent.createChooser(intent, "Select Image"),438)
                }

                if (i == 1){
                    checker = "Videos"
                    val intent = Intent(Intent.ACTION_GET_CONTENT)
                    intent.type = "video/*"
                    startActivityForResult(Intent.createChooser(intent, "Select Video"),439)
                }

                if (i == 2){
                    checker = "File Documents"
                    val intent = Intent(Intent.ACTION_GET_CONTENT)
                    intent.type = "application/pdf"
                    startActivityForResult(Intent.createChooser(intent, "Select File Documents"),440)
                }
            })
        builder.show()
    }

您需要像这样设置数组适配器。

val builder = AlertDialog.Builder(this@ChatLogActivity)

val arrayAdapter = ArrayAdapter<String>(
    this,
    android.R.layout.select_dialog_singlechoice)
    arrayAdapter.add("Images")
    arrayAdapter.add("Videos")
    arrayAdapter.add("Documents")

builder.setTitle("Select One Option")

builder.setAdapter( arrayAdapter
    ) { _, i ->
        if (i == 0){
            checker = "Images"
            val intent = Intent(Intent.ACTION_GET_CONTENT)
            intent.type = "image/*"
            startActivityForResult(Intent.createChooser(intent, "Select Image"),438)
        }

        if (i == 1){
            checker = "Videos"
            val intent = Intent(Intent.ACTION_GET_CONTENT)
            intent.type = "video/*"
            startActivityForResult(Intent.createChooser(intent, "Select Video"),439)
        }

        if (i == 2){
            checker = "File Documents"
            val intent = Intent(Intent.ACTION_GET_CONTENT)
            intent.type = "application/pdf"
            startActivityForResult(Intent.createChooser(intent, "Select File Documents"),440)
        }
    }
builder.show()