Single Alert Dialouge Box for Multiple Button in android code example

Example: how to do multiple button dialog kotlin

// kotlin code alert dialog builder with multiple buttons
// context = this or applicationContext
val dialog = AlertDialog.Builder(context)
val bNames = arrayOf<CharSequence>("button 1", "button 2", "button 3")
dialog.setTitle("CHOOSE ACTION")
dialog.setItems(bNames) { _, which ->
  when (which) {
    0 -> Toast.makeText(context, "clicked 1", Toast.LENGTH_SHORT).show();
    1 -> Toast.makeText(context, "clicked 2", Toast.LENGTH_SHORT).show();
    2 -> Toast.makeText(context, "clicked 3", Toast.LENGTH_SHORT).show();
  }
}.create()
// for more actions...
dialog.setNegativeButton("Cancel") { _, _ -> }
dialog.show()