本文介绍了如何在Xamarin.Android警报对话框中显示ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Android警报对话框中显示Listview.
I want display Listview inside the Android Alert Dialog.
请帮助我
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();
}
推荐答案
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();
这篇关于如何在Xamarin.Android警报对话框中显示ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!