VOOZH about

URL: https://www.geeksforgeeks.org/android/alert-dialog-with-multipleitemselection-in-android/

⇱ Alert Dialog with MultipleItemSelection in Android - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Alert Dialog with MultipleItemSelection in Android

Last Updated : 23 Jul, 2025

In the previous article Alert Dialog with SingleItemSelection in Android, we have seen how the alert dialog is built for single item selection. In this article, it's been discussed how to build an alert dialog with multiple item selection. Multiple Item selection dialogs are used when the user wants to select multiple items at a time. Have a look at the following image to differentiate between Single Item selection and Multiple Item selection alert dialogs.

👁 Alert Dialog with MultipleItemSelection in Android


Implementation of Alert Dialog with MultipleItemSelection

Step 1: Create a New Project in Android Studio

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

The code for that has been given in both Java and Kotlin Programming Language for Android.


Step 2: Working with the XML Files

Next, go to the activity_main.xml file, which represents the UI of the project. Below is the code for the activity_main.xml file. Comments are added inside the code to understand the code in more detail.

activity_main.xml:

Design UI:

👁 output-ui-alert-box-multiselect


Step 3: Working with the MainActivity File

Go to the MainActivity File and refer to the following code. Below is the code for the MainActivity File. Comments are added inside the code to understand the code in more detail.

👁 Alert-Dialog-with-MultipleItemSelection-in-Android


The function that needs to implement the multiple item selection for alert dialog is discussed below.

Syntax:

// documentation code
public Builder setMultiChoiceItems(Char Sequence[] items, Boolean[] checkedItems, final OnMultiChoiceClickListener listener) {
// other codes here
}

// your implementation
builder.setMultiChoiceItems(items, checkedItems) { dialog, which, isChecked ->
// your code here
}

Parameters:

  • items – the text of the items to be displayed in the list.
  • checkedItems – specifies which items are checked. It should be null in which case no items are checked. If non null it must be exactly the same length as the array of items.
  • listener – notified when an item on the list is clicked. The dialog will not be dismissed when an item is clicked. It will only be dismissed if clicked on a button, if no buttons are supplied it's up to the user to dismiss the dialog.

Invoke the following code to implement the things. Comments are added for better understanding.

Output:

Comment

Explore