如何在Xamarin.Android警报对话框中显示ListView?

时间:2018-03-27 09:54:03

标签: xamarin xamarin.forms xamarin.ios xamarin.android

我希望在Android警报对话框中显示Listview。

请帮助我任何人

  void SetDialog(IList<OrderInfo> orders, string contactGuid){

        var dialogView = this.BindingInflate(Resource.Layout.guest_name_list, null);

        var dialog = new AlertDialog.Builder(this.Context);
        dialog.SetView(dialogView);
        dialog.SetNegativeButton("Cancel", (s, a) => { });
        AlertDialog alertDialog = dialog.Create();
        alertDialog.Show();

        dialogView.FindViewById<TextView>(Resource.Id.AlertTitle).SetText(PartyDetailsViewModel.EditAddOrderActionTitle, null);
        dialogView.FindViewById<TextView>(Resource.Id.AlertTitleMessage).SetText(PartyDetailsViewModel.EditAddOrderActionMessage, null);
        dialogView.FindViewById<TextView>(Resource.Id.AddOrderButton).SetText(PartyDetailsViewModel.AddOrderButtonTitle, null);
        dialogView.FindViewById<TextView>(Resource.Id.AddOrderButton).Click += delegate {
            this.ViewModel.SelectedOrder = (PartyDetailsViewModel.AddOrderButtonTitle, contactGuid);
            alertDialog.Dismiss();
        };
       dialogView.FindViewById<ListView>(Resource.Id.GuestNameList).SetAdapter();
    }

1 个答案:

答案 0 :(得分:2)

Dialog / ListView示例:

var dialogView = LayoutInflater.Inflate(Resource.Layout.guest_name_list, null);
AlertDialog alertDialog;
using (var dialog = new AlertDialog.Builder(this))
{
    dialog.SetView(dialogView);
    dialog.SetNegativeButton("Cancel", (s, a) => { });
    alertDialog = dialog.Create();
}
var items = new string[] { "Stack", "Over", "Flow" };
var adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, items);
dialogView.FindViewById<ListView>(Resource.Id.GuestNameList).Adapter = adapter;
alertDialog.Show();