【问题标题】:How can I display ListView in Xamarin.Android Alert Dialog?如何在 Xamarin.Android 警报对话框中显示 ListView?
【发布时间】:2018-03-27 22:21:40
【问题描述】:

我想在 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();
    }

【问题讨论】:

  • 对话框是内置的文本消息。使用表单,可能是this PopUp plugin fits for you
  • 您是指 ActionSheet 吗?
  • 除了没有为您的 ListView 提供适配器之外,究竟是什么问题(?)?还是使用Adapter 属性与SetAdaptor 方法?

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


【解决方案1】:

对话框/列表视图示例:

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

【讨论】:

    猜你喜欢
    • 2023-03-25
    • 1970-01-01
    • 2019-04-21
    • 1970-01-01
    • 1970-01-01
    • 2011-01-08
    • 2023-03-13
    • 2020-01-14
    相关资源
    最近更新 更多