how to create a multiple alert dialog in kotlin
fun withMultiChoiceList(view: View) { val items = arrayOf("Microsoft", "Apple", "Amazon", "Google") val selectedList = ArrayList<Int>() val builder = AlertDialog.Builder(this) builder.setTitle("This is list choice dialog box") builder.setMultiChoiceItems(items, null ) { dialog, which, isChecked -> if (isChecked) { selectedList.add(which) } else if (selectedList.contains(which)) { selectedList.remove(Integer.valueOf(which)) } } builder.setPositiveButton("DONE") { dialogInterface, i -> val selectedStrings = ArrayList<string>() for (j in selectedList.indices) { selectedStrings.add(items[selectedList[j]]) } Toast.makeText(applicationContext, "Items selected are: " + Arrays.toString(selectedStrings.toTypedArray()), Toast.LENGTH_SHORT).show() } builder.show() }
Source: www.journaldev.com