Answers for "how to do multiple button dialog kotlin"

0

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()
Posted by: Guest on November-10-2020

Code answers related to "how to do multiple button dialog kotlin"

Browse Popular Code Answers by Language