如何强制select alertDialog 中的项目?

How to make it mandatory to select an item in alertDialog?

在我的项目中,我为 select 加油站的用户创建了一个警报,该字段是必填字段。如何禁用侧面的点击,或者如果用户没有 select 关闭 activity?

我的提醒:

val builder = AlertDialog.Builder(this)
        builder.setTitle("Selecione um Posto")
        builder.setItems(listaNomePostos) { dialog, which ->
            for (i in listaPostos) {
                if (i.name1 == listaNomePostos[which]) {
                    conexaoAPI.stationAbastecer = i.station
                    texto_nome_posto_topo_formulario.text = i.name1
                }

            }
        }
        val dialog: AlertDialog = builder.create()
        dialog.show()

dialog.setCancelable(false) 会做到