我对MonoDroid / Android开发还很陌生,我想知道是否有人可以指点我的示例或解释如何使用自定义ListView创建AlertDialog?
我需要一个带图像的名字列表。我能够创建一个带有列表的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();
但我真的需要有一个与每个项目关联的图像,这就是为什么我希望我可以使用带有ListView的AlertDialog。
感谢您的帮助!!
答案 0 :(得分:3)
您可以将自定义View
添加到Dialog
。因此,您可以制作自定义ListView
Adapter
,使用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();
自己的。
{{1}}