Set a list of items to be displayed in the dialog as the content, you will be notified of the selected item via the supplied listener.
Returns: This Builder object to allow for chaining of calls to set methods
1. Create an AlertDialog with Supplied Arguments
2. Initialize a CharSequence Array named myCharSequence.
3. Add the line below to the imports section.
import android.content.DialogInterface;
4. After your AlertDialog.Builder is instantiated in step 1, add the following code to set a list of items to an AlertDialog.
@Override
public void onClick(DialogInterface dialog, int which) {
// To test, Add a Toast, with a context of getBaseContext() and a message such as // "You selected " + myCharSequence[which]" //<- This will display the item in the list
// "You selected " + which //<- this will just display the number order of the item selected in the list
}
});
5. Compile and run!
Next Recommended Article: How to Add a List of Items with Radio Buttons to AlertDialog.Builder
Resources:
http://developer.android.com/reference/android/app/AlertDialog.Builder.html#setItems(java.lang.CharSequence[], android.content.DialogInterface.OnClickListener)
http://androiddesk.wordpress.com/tag/alert-dialog-with-list-of-items/