0

I am fairly new to MonoDroid/Android Development and I was wondering if anyone can point me to a sample or explain how I would go about creating an AlertDialog with a custom ListView?

I need to have a list of names with images. I am able to create an AlertDialog with a list as follows:

List<string> sPeople = new List<string>();
for (int ndx = 0; ndx < od.PeopleAtLoc.Count; ndx++)
{
    ObjectPeople d = od.PeopleAtLoc[ndx];
    sPeople.Add (d.Name + "\n" + d.Type);
}
string[] stuff = sPeople.ToArray();

new AlertDialog.Builder(this)
    .SetTitle("Choose a Person:")
        .SetItems(stuff, (sender, args) => 
                  { 
            _bInDetails = true;
            Intent intent = new Intent(this, typeof(FindAPersonDetailActivity));
                                intent.PutExtra("PERSON_ID", od.PeopleAtLoc[(int)args.Which].ID);
                                intent.PutExtra ("PERSON_CITY", od.PeopleAtLoc[(int)args.Which].City);
            StartActivity(intent);
        })
        .Show();

But I really need to have an image associated with each item which is why I was hoping I could use an AlertDialog with a ListView.

Thanks for any help!!

LilMoke
  • 3,176
  • 7
  • 48
  • 88

1 Answers1

3

You can add custom Views to Dialogs. So you could make a custom ListView Adapter, create a view with a ListView, inflate it, add it to the Dialog and set the Adapter to your own.

var customView = LayoutInflater.Inflate (Resource.Layout.CustomDialogListView, null);
var listView = (ListView) customView.FindViewById(Resource.Id.ListView);
listView.Adapter = new MyListViewAdapter(stuff);

var builder = new AlertDialog.Builder(this);
builder.SetView(customView);
builder.SetPositiveButton(Resource.String.dialog_ok, OkClicked);
builder.SetNegativeButton(Resource.String.dialog_cancel, CancelClicked);

return builder.Create();
Cheesebaron
  • 24,131
  • 15
  • 66
  • 118
  • Yes, I did figure it out, but thanks for the input. Since I did this and it worked, but you suggested the same solution, I will mark it as solved. Thank you again. – LilMoke Mar 14 '13 at 20:54