Sunday, 5 October 2014

Android: ListView inside an AlertDialog

In this tutorial we show how to create a list inside an alert dialog.

The items of the list are defined in the class and are made of a title and a subtitle.
When the application is started, it's created an Arraylist with 3 elements of this type.

The main activity is implemented in

The layout of the alert dialog is defined in list_dialog.xml:

The layout of the single item of the list is defined in component.xml:

The adapter for the correspondence between the layout and the list is defined in

You can download the complete example from our repository: Download

The final result is the following: