How can I display ListView in Xamarin.Android Alert Dialog?

半世苍凉 提交于 2019-12-11 10:08:18

问题


I want display Listview inside the Android Alert Dialog.

Please help me any one

  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:


Dialog/ListView Example:

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


来源:https://stackoverflow.com/questions/49509738/how-can-i-display-listview-in-xamarin-android-alert-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!