Adding a list to an Android AlertDialog

This is a repost of an answer I wrote on Stack Overflow.

An AlertDialog is a convenient way to solicit a response from a user. However, sometimes the standard positive, negative, and neutral button format isn’t what you want. This post will show you how to add a list of choices to your AlertDialog.

According to the documentation, there are three kinds of lists that can be used with an AlertDialog:

  1. Traditional single-choice list
  2. Persistent single-choice list (radio buttons)