How can I display a list view in an Android Alert Dialog?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Displaying a list inside an Android AlertDialog is a common pattern for quick choice menus, filters, and simple pickers. The right implementation depends on how complex the list needs to be: setItems is great for a basic list, setAdapter gives more control, and a custom view is better when the dialog needs richer UI behavior.
The Simplest Option: setItems
If all you need is a short list of text choices, AlertDialog.Builder.setItems(...) is the cleanest solution.
This already gives you a dialog with a list-like presentation and item click callback. For many use cases, you do not need to create a literal ListView yourself.
Using setAdapter for More Control
If you want a custom adapter or more control over row rendering, use setAdapter.
This still uses the dialog’s built-in list handling, but it lets you choose the row layout and adapter behavior.
When You Truly Need a ListView
A real embedded ListView makes sense when the dialog content is more customized than the builder shortcuts allow.
This approach is more flexible, but it also means you are responsible for wiring the list behavior yourself.
Prefer DialogFragment for Lifecycle Safety
If the dialog is more than a quick inline prompt, consider showing it from a DialogFragment. That keeps the dialog tied more cleanly to fragment lifecycle and configuration changes.
For simple examples, an inline AlertDialog.Builder is fine. For production dialogs that can survive rotation or integrate with a ViewModel, DialogFragment is often the better long-term design.
Single-Choice and Multi-Choice Lists
If the dialog represents a selection state rather than a plain click action, AlertDialog.Builder also has dedicated APIs such as setSingleChoiceItems and setMultiChoiceItems. Those are often a better fit than embedding a raw ListView, because the builder manages the checked-state UI for you. In other words, pick the dialog API that matches the interaction pattern before reaching for a custom view.
Performance and UX Considerations
A dialog is good for short or medium lists. For long, searchable, or highly interactive lists, a full screen or bottom sheet often provides a better experience than squeezing a complex list into an alert dialog.
That is an important design question, not just an implementation detail. The technically possible UI is not always the best UI.
Common Pitfalls
- Building a custom
ListViewwhensetItemswould have solved the problem adds unnecessary code. - Putting a very large list in an alert dialog makes the UI harder to use.
- Forgetting to dismiss the dialog after item selection can feel awkward for one-shot choices.
- Using an activity context incorrectly from detached fragments can cause dialog errors.
- Ignoring configuration changes makes inline dialog code harder to maintain over time.
Summary
- Use
setItemsfor the simplest text-choice dialog. - Use
setAdapterwhen you need adapter-level customization. - Use a custom
ListViewonly when the built-in shortcuts are too limited. - Consider
DialogFragmentwhen lifecycle handling matters. - Keep alert-dialog lists short and focused for the best user experience.

