Home > Enterprise >  How to make it mandatory to select an item in alertDialog?
How to make it mandatory to select an item in alertDialog?

Time:04-20

In my project I created an alert for the user to select a gas station, and this field is mandatory. How do I disable the click on the sides or if the user does not select anything close the activity?

My alert:

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()

CodePudding user response:

dialog.setCancelable(false) will do it

  • Related