0

私は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を使用できることを望んでいました。

助けてくれてありがとう!

4

1 に答える 1

3

Viewカスタムをsに追加できます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();
于 2013-03-14T16:18:29.517 に答える