2013-03-14 69 views
0

我對MonoDroid/Android開發相當新,我想知道是否有人可以指向我的示例或解釋我將如何去創建AlertDialog與自定義ListView?MonoDroid AlertDialg與ListView

我需要有圖像的名稱列表。我能夠與列表中創建一個AlertDialog如下:

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(); 

但我真的需要有這就是爲什麼我希望我可以用一個AlertDialog有一個ListView每個項目相關聯的圖像。

感謝您的任何幫助!

回答

3

您可以將自定義View s添加到Dialog s。因此,您可以自定義ListViewAdapter,使用ListView創建視圖,將它膨脹,將其添加到Dialog並將Adapter設置爲您自己的視圖。

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(); 
+0

是的,我弄明白了,但感謝您的意見。既然我做到了這一點,它的工作,但你提出了同樣的解決方案,我會標記爲解決。再次感謝你。 – LilMoke 2013-03-14 20:54:38